DependencyPropert not set from XAML with DynamicResource as parameter
I am trying to develop a custom custom three state control and so far I have been using CTF to set properties.
But I would like to change this to use the WPF property system with PropertiesDependencies.
Unfortunately I am unable to get it to work, when I set a property from my xaml (father) with DynamicResource, no value is set.
<common:StateImageButton x:Name="story_buttonRecord" BackTest="{DynamicResource backTest}" />
Here is the code I have in my button controller:
public ImageSource BackTest
{
get { return (ImageSource)this.GetValue(BackProp); }
set { this.SetValue(WidthProp,value); }
}
public static readonly DependencyProperty BackProp =
DependencyProperty.Register(
"BackTest",
typeof(ImageSource),
typeof(StateImageButton),
new FrameworkPropertyMetadata());
I am not yet using the property in my xaml button, but apparently it is not even included in Setter. I have searched a lot online with no success. So maybe I missed something.
Thanks in advance for your help, Boris
a source to share
Also, WPF doesn't use a setter to set a property, it does it directly.
The way to debug when WPF sets a property is to add a callback when the property is set like this.
public static readonly DependencyProperty BackProp =
DependencyProperty.Register(
"BackTest",
typeof(ImageSource),
typeof(StateImageButton),
new FrameworkPropertyMetadata(OnBackChanged));
private static void OnBackChanged(
DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
var sender = (StateImageButton)d; // Put a breakpoint here
}
a source to share