Wpf 跟踪属性更改事件
我有一个视图,几乎没有如下控件:Wpf 跟踪属性更改事件,wpf,c#-4.0,Wpf,C# 4.0,我有一个视图,几乎没有如下控件: <c:DropTargetContentControl Content="{Binding FavoriteTool1, Mode=TwoWay}" ContentTemplate="{StaticResource FavoriteTemplate}" Margin="5,0"/> <c:DropTargetContentControl Content="{Binding FavoriteTool2, Mode=TwoWay}" Conte
<c:DropTargetContentControl Content="{Binding FavoriteTool1, Mode=TwoWay}" ContentTemplate="{StaticResource FavoriteTemplate}" Margin="5,0"/>
<c:DropTargetContentControl Content="{Binding FavoriteTool2, Mode=TwoWay}" ContentTemplate="{StaticResource FavoriteTemplate}" Margin="5,0"/>
<c:DropTargetContentControl Content="{Binding FavoriteTool3, Mode=TwoWay}" ContentTemplate="{StaticResource FavoriteTemplate}" Margin="5,0"/>
FavoriteTool1、FavoriteTool2、FavoriteTool3
是viewmodel中的属性
当DropTargetContentControl
发生任何更改时,这些属性将引发其PropertyChanged
事件。当我从ViewModel中设置一些值时,也会引发这些PropertyChanged
。只有当由于DropTargetContentControl
中的更改而引发PropertyChanged
时,我才需要调用一些函数
有什么建议我如何跟踪propertychanged事件吗?我没有在视图级别更改任何内容的灵活性。如果您有一个实现了
INotifyPropertyChanged
接口的类,那么您可以将处理程序附加到该类中实现的INotifyPropertyChanged.PropertyChanged
事件:
YourViewModel.PropertyChanged += YourViewModel_PropertyChanged;
...
private void YourViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// e.PropertyName holds the name of the changed property
}