绑定到父控件属性时,子WPF控件的绑定不会更新

问题描述:

我有我已经定义的UserControl(Pager1)。在这个控制中,我已经定义了属性TotalRecords。我有另一个UserControl(ListDisplay),它包含Pager1的一个实例。我尝试将Pager1的TotalRecords绑定到ListDisplay的属性ParentTotalRecords。我没有收到任何错误,但从未更新过TotalRecords绑定到父控件属性时,子WPF控件的绑定不会更新

任何人都可以向我解释为什么这不起作用,以及如何让它工作?

谢谢。

<UserControl x:Class="MyApp.ListDisplay" 
     xmlns:local="clr-namespace"> 

<local:Pager1 x:Name="pgrPager" 
    TotalRecords="{Binding ParentTotalRecords}" /> <!-- This binding does not update --> 
</UserControl> 
+0

它是“从未更新过”还是“从未设置过”?这两者在调试方面存在巨大差异。 – 2011-04-07 21:57:02

可能是更改通知的问题?是否实施了适当的界面? (MSDN

试试这个。

<UserControl x:Class="MyApp.ListDisplay" 
      x:Name="root" 
      xmlns:local="clr-namespace"> 

    <local:Pager1 x:Name="pgrPager" 
        TotalRecords="{Binding Path=ParentTotalRecords, ElementName=root}" /> 
</UserControl> 

,当然还有,确保ParentTotalRecords是DependancyProperty和总记录也是一个DependencyProperty。

+0

不需要是DP,只需要实现INotify – Wobbles 2017-01-19 15:43:57