I am trying to override the value of a dependency property but it doesn't seem to be working.
In my Xaml code I have a button with the following CommandParameter :
CommandParameter="{Binding State,Mode=OneWay}
and here I declare my dependency property:
public class MyStateControl : UserControl
{
public MyStateControl()
{
this.InitializeComponent();
}
public string State
{
get { return (string)this.GetValue(StateProperty); }
set { this.SetValue(StateProperty, value); }
}
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(
"State", typeof(string), typeof(MyStateControl),new PropertyMetadata("DEFAULT"));
}
and then here I try to get that value to use it, after overriding it. When I press the button, onMyCommandExecuted gets called. and the value of obj is "DEFAULT"
public class MyAdvancedStateControl : INotifyPropertyChanged
{
public MyAdvancedStateControl()
{
MyStateControl.StateProperty.OverrideMetadata(typeof(MyAdvancedStateControl), new PropertyMetadata("Successfully overriden"));
}
private void onMyCommandExecuted(object obj)
{
//TODO
}
}
Am I doing something wrong? If so, what's the best way to override the value of a dependency property? And would it be possible/ probably better to set the default value as a variable that I can then change easily from MyAdvancedStateControl? Thank you