views:

131

answers:

1

I have this DP:

    public bool ShowEntireHierarchyEx
    {
        get { return (bool)GetValue(ShowEntireHierarchyExProperty); }
        set { SetValue(ShowEntireHierarchyExProperty, value); }
    }

    public static readonly DependencyProperty ShowEntireHierarchyExProperty =
        DependencyProperty.Register("ShowEntireHierarchyEx", typeof(bool), typeof(CustomizeStatisticsStyleControl), new UIPropertyMetadata(false));

And I'm binding it to this checkbox in XAML:

<CheckBox Margin="16,5,0,0" x:Name="checkBoxHierarcy"
          IsChecked="{Binding ElementName=customizeStatisticsStyle, Path=ShowEntireHierarchyEx, Mode=TwoWay}">
    S_how entire gate hierarchy
</CheckBox>

But for some reason the checkbox does not change the ShowEntireHierarchy property, but if the ShowEntireHierarchy property changes in code, the CheckBox does change. What am I missing here?

Thanks!

+1  A: 

The reason SetValue is not being called is that dependency property bindings do NOT go through the CLR setter. A bound DP is updated "behind the scenes" by WPF, i.e. directly in a private "slot" managed by the DP system.

It's therefore probable that your DP is being set when the check box changes. The setter breakpoint not being hit shouldn't concern you. You should only worry if you have some other reason to believe that the DP is not being updated.

To break on changes in a bound DP, add a PropertyChangedCallback in your property metadata, and set a breakpoint in that callback.

itowlson
That is exactly what I was doing right now. Thanks! (However breakpoints do work on other DP, but the solution IS using PropertyChangedCallback anyways).
Carlo
Breakpoints in the getter and setter will be hit if you access the DP through code (e.g. `myControl.ShowHierarchy = true;`), because those *do* go through the CLR wrapper property. It's only when WPF is updating the DP (through binding, animation, styling, etc.) that the setter gets bypassed. That might explain why you're seeing breakpoints being hit on other DPs -- hope it makes more sense now!
itowlson
Oh I see, it does make sense. Thanks a lot for the info!
Carlo