开发者

checkbox not setting dependency property

I have this DependencyProperty:

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

public static readonly DependencyProperty ShowEntireHierarc开发者_如何学GohyExProperty =
    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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜