views:

250

answers:

1

Hello,

I'm trying to develop a custom tri-state button user control and so far I've been using CTF to set properties.
But I would like to change this to be using the WPF property system with PropertiesDependencies.

Unfortunately I don't manage to make it work, when I set the property from my xaml (father) using a DynamicResource, the value is not 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 don't even use the property in my button xaml yet, but it apparently doesn't even enter in the Setter. I've been searching a lot online without success. So maybe I'm missing something .

Thanks in advance for your help, Boris

A: 

Also, WPF doesn't use the setter provided to set a property, it does it directly.

The way to debug when WPF sets a property is to add a callback for when the property is set, like so.

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
}
Cameron MacFarland
Thanks, the value was set correctly actually, and for the record it is possible to set DynamicRecords as parameters for custom properties.
Boris Gougeon