Problem Bindung einer inneren Benutzersteuerungseigenschaft an eine äußere Benutzersteuerungseigenschaft [Duplikat]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Problem Bindung einer inneren Benutzersteuerungseigenschaft an eine äußere Benutzersteuerungseigenschaft [Duplikat]

Post by Anonymous »

Ich platziere eine Benutzersteuerung in eine Benutzersteuerung und habe Probleme, die innere Abhängigkeitseigenschaft an eine äußere Abhängigkeitseigenschaft zu binden. Ich verwende .NET 8. Es ist wahrscheinlich etwas Dummes, das ich fehlt, aber ich kann es einfach nicht sehen. In der äußeren Benutzerkontrolle habe ich eine Abhängigkeitseigenschaft namens Hourval. In der äußeren Benutzerkontrolle XAML versuche ich, die Eigenschaft des inneren Steuerelements an die Eigenschaft des Außensteuerns zu binden, aber wenn sich die Eigenschaft des inneren Steuerelements ändert, verbreitet sie sich nicht an die äußere Steuerelement-Eigenschaft.

Code: Select all




















< /code>
Der innere Code dahinter: < /p>
namespace WpfUserControls.UserControls
{
/// 
/// Interaction logic for UcIntegerPicker.xaml
/// 
public partial class UcIntegerPicker : UserControl
{
#region Constructor

public UcIntegerPicker()
{
InitializeComponent();
}

#endregion Constructor

#region Dependancy Properties

public int LowerLimit
{
get { return (int)GetValue(LowerLimitProperty); }
set { SetValue(LowerLimitProperty, value); }
}

// Using a DependencyProperty as the backing store for LowerLimit.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty LowerLimitProperty =
DependencyProperty.Register("LowerLimit", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

public int UpperLimit
{
get { return (int)GetValue(UpperLimitProperty); }
set { SetValue(UpperLimitProperty, value); }
}

// Using a DependencyProperty as the backing store for UpperLimit.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty UpperLimitProperty =
DependencyProperty.Register("UpperLimit", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

public int CurrentVal
{
get { return (int)GetValue(CurrentValProperty); }
set
{
SetValue(CurrentValProperty, value);
string strVal = value.ToString();
if (strVal != CurrentStr)
{
CurrentStr = strVal;
}
}
}

// Using a DependencyProperty as the backing store for CurrentVal.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty CurrentValProperty =
DependencyProperty.Register("CurrentVal", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

public string CurrentStr
{
get { return (string)GetValue(CurrentStrProperty); }
set
{
SetValue(CurrentStrProperty, value);
Int32 intVal = Convert.ToInt32(value);
if (intVal != CurrentVal)
{
CurrentVal = intVal;
}
}
}

// Using a DependencyProperty as the backing store for CurrentStr.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty CurrentStrProperty =
DependencyProperty.Register("CurrentStr", typeof(string), typeof(UcIntegerPicker), new PropertyMetadata("0"));

public string ButtonLabel
{
get { return (string)GetValue(ButtonLabelProperty); }
set { SetValue(ButtonLabelProperty, value); }
}

// Using a DependencyProperty as the backing store for ButtonLabel.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ButtonLabelProperty =
DependencyProperty.Register("ButtonLabel", typeof(string), typeof(UcIntegerPicker), new PropertyMetadata(" H "));

public int TextBlockWidth
{
get { return (int)GetValue(TextBlockWidthProperty); }
set { SetValue(TextBlockWidthProperty, value); }
}

// Using a DependencyProperty as the backing store for TextBlockWidth.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextBlockWidthProperty =
DependencyProperty.Register("TextBlockWidth", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

public int TextBlockHeight
{
get { return (int)GetValue(TextBlockHeightProperty); }
set { SetValue(TextBlockHeightProperty, value); }
}

// Using a DependencyProperty as the backing store for TextBlockHeight.   This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextBlockHeightProperty =
DependencyProperty.Register("TextBlockHeight", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

public int TextBlockFontSize
{
get { return (int)GetValue(TextBlockFontSizeProperty); }
set { SetValue(TextBlockFontSizeProperty, value); }
}

// Using a DependencyProperty as the backing store for TextBlockFontSize.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextBlockFontSizeProperty =
DependencyProperty.Register("TextBlockFontSize", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

public int SliderWidth
{
get { return (int)GetValue(SliderWidthProperty); }
set { SetValue(SliderWidthProperty, value); }
}

// Using a DependencyProperty as the backing store for SliderWidth.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty SliderWidthProperty =
DependencyProperty.Register("SliderWidth", typeof(int), typeof(UcIntegerPicker), new PropertyMetadata(0));

#endregion Dependancy Properties

#region Private Methods

private void ButtonChange_Click(object sender, RoutedEventArgs e)
{
popSlider.IsOpen = true;
sliderSetting.Focus();
}

private void SliderSetting_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
CurrentVal = ((Int32)e.NewValue);
}

private void SliderSetting_LostFocus(object sender, RoutedEventArgs e)
{
popSlider.IsOpen = false;
}

#endregion Private Methods
}
}
< /code>
Die äußere Benutzersteuerung XAML: < /p>





< /code>
Der äußere Code dahinter: < /p>
namespace WpfUserControls.UserControls
{
/// 
/// Interaction logic for UcTimePicker24.xaml
/// 
public partial class UcTimePicker24 : UserControl
{
#region Constructor

public UcTimePicker24()
{
InitializeComponent();
TimeVal = new TimeOnly(7, 8, 9, 5);
}

#endregion Constructor

#region Dependancy Properties

public int TextBlockHeight
{
get { return (int)GetValue(TextBlockHeightProperty); }
set { SetValue(TextBlockHeightProperty, value); }
}

// Using a DependencyProperty as the backing store for TextBlockHeight.   This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextBlockHeightProperty =
DependencyProperty.Register("TextBlockHeight", typeof(int), typeof(UcTimePicker24), new PropertyMetadata(10));

public int TextBlockWidth
{
get { return (int)GetValue(TextBlockWidthProperty); }
set { SetValue(TextBlockWidthProperty, value); }
}

// Using a DependencyProperty as the backing store for TextBlockWidth.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextBlockWidthProperty =
DependencyProperty.Register("TextBlockWidth", typeof(int), typeof(UcTimePicker24), new PropertyMetadata(10));

public int TextBlockFontSize
{
get { return (int)GetValue(TextBlockFontSizeProperty); }
set { SetValue(TextBlockFontSizeProperty, value); }
}

// Using a DependencyProperty as the backing store for TextBlockFontSize.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextBlockFontSizeProperty =
DependencyProperty.Register("TextBlockFontSize", typeof(int), typeof(UcTimePicker24), new PropertyMetadata(8));

public TimeOnly TimeVal
{
get { return (TimeOnly)GetValue(TimeValProperty); }
set
{
SetValue(TimeValProperty, value);
Int32 hour = value.Hour;
if (hour != HourVal)
{
HourVal = hour;
}
}
}

// Using a DependencyProperty as the backing store for TimeVal.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty TimeValProperty =
DependencyProperty.Register("TimeVal", typeof(TimeOnly), typeof(UcTimePicker24), new PropertyMetadata(TimeOnly.MinValue));

public Int32 HourVal
{
get { return (Int32)GetValue(HourValProperty); }
set
{
SetValue(HourValProperty, value);
if (TimeVal.Hour != value)
{
TimeVal = new TimeOnly(value, TimeVal.Minute, TimeVal.Second, TimeVal.Millisecond);
}
string strVal = value.ToString();
if (strVal != HourStr)
{
HourStr = strVal;
}
}
}

// Using a DependencyProperty as the backing store for HourVal.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty HourValProperty =
DependencyProperty.Register("HourVal", typeof(Int32), typeof(UcTimePicker24), new PropertyMetadata(0));

public string HourStr
{
get { return (string)GetValue(HourStrProperty); }
set
{
SetValue(HourStrProperty, value);
Int32 intVal = Convert.ToInt32(value);
if (intVal != HourVal)
{
HourVal = intVal;
}
}
}

// Using a DependencyProperty as the backing store for HourStr.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty HourStrProperty =
DependencyProperty.Register("HourStr", typeof(string), typeof(UcTimePicker24), new PropertyMetadata("0"));

#endregion Dependancy Properties

#region Private Methods

#endregion Private Methods
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post