Dependency property is not working for me on a WPF UserControl?

In the XAML you are setting the Fillbrush value on TestUserControl to Red, but when the button is clicked it shows the Fillbrush value for Window2 not TestUserControl . And since the Fillbrush value for Window2 is not set in XAML it still has the default value of Yellow.

Up vote 0 down vote favorite share g+ share fb share tw.

I created my own user control with dependency properties and added it to my main window, where I now want to be able set the dependency properties. The properties are not taking the value I set in the XAML of the main window and I am not sure what I am missing. In the code I set the default value for the FillBrush property to Yellow.

In the XAML I set it to Red. When I click the Test button, it shows the property to be Yellow. Here is the code: Window XAML Window Code Behind public partial class Window2 : Window { public static readonly DependencyProperty FillBrushProperty = DependencyProperty.

Register("FillBrush", typeof(Brush), typeof(Window2), new UIPropertyMetadata(Brushes. Yellow)); public Brush FillBrush { get { return (Brush)GetValue(FillBrushProperty); } set { SetValue(FillBrushProperty, value); } } public Window2() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { this.debugTextBox. Text = "Red: " + Brushes.

Red + " Yellow: " + Brushes. Yellow + " Actual: " + this. FillBrush; } } User Control XAML User Control Code Behind public partial class TestUserControl : UserControl { public static readonly DependencyProperty FillBrushProperty = DependencyProperty.

Register("FillBrush", typeof(Brush), typeof(TestUserControl), new UIPropertyMetadata(Brushes. Cyan)); public Brush FillBrush { get { return (Brush)GetValue(FillBrushProperty); } set { SetValue(FillBrushProperty, value); } } public TestUserControl() { InitializeComponent(); } } What am I missing? C# wpf xaml usercontrols dependency-properties link|improve this question asked Feb 2 at 2:36Elan926824 68% accept rate.

In the XAML you are setting the Fillbrush value on TestUserControl to Red, but when the button is clicked it shows the Fillbrush value for Window2, not TestUserControl. And since the Fillbrush value for Window2 is not set in XAML it still has the default value of Yellow.

Oh, geez! That was seriously messed up, my bad! – Elan Feb 2 at 4:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions