将绑定中的 NotifyOnTargetUpdated 或 NotifyOnSourceUpdated 属性(或两者)设置为 true。您提供的用于侦听此事件的处理程序必须直接附加到您希望收到更改通知的元素,或者如果您希望在上下文中的任何内容发生变化时得到通知,则附加到整个数据上下文。
<TextBlock Grid.Row=“1” Grid.Column= “1” Name= “RentText” Text= "{Binding Path=Rent, Mode=OneWay, NotifyOnTargetUpdated=True}"TargetUpdated= “OnTargetUpdated” />
若要从对象的个别属性清除绑定,请按下例所示调用 ClearBinding。下面的示例会从 mytext 的 TextProperty 中移除绑定,前者是一个 TextBlock 对象。
BindingOperations.ClearBinding(myText, TextBlock.TextProperty);
查找由 DataTemplate 生成的元素:
<ListBox Name = “myListBox” ItemTemplate="{StaticResource myDataTemplate}"IsSynchronizedWithCurrentItem=“True”>
<ListBox.ItemsSource><Binding Source = "{StaticResource InventoryData}"XPath=“Books/Book”/></ListBox.ItemsSource>