2013-10-24 63 views
0

我有一些控件视图如下图所示:轨道PropertyChanged事件

<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"/> 

FavouriteTool1, FavouriteTool2, FavouriteTool3在视图模型的属性。

DropTargetContentControl有任何变化时,这些属性会提高它们的PropertyChanged事件。当我从ViewModel设置一些值时,也会产生这些PropertyChanged。我只需要在PropertyChanged由于DropTargetContentControl的变化而产生时调用一些函数。

任何建议如何跟踪propertychanged事件?我没有灵活性来改变视图级别的任何内容。

回答

0

如果你有一个实现了INotifyPropertyChanged接口的类,那么你可以附加一个句柄到INotifyPropertyChanged.PropertyChanged事件是在类中实现:

YourViewModel.PropertyChanged += YourViewModel_PropertyChanged; 

... 

private void YourViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) 
{ 
    // e.PropertyName holds the name of the changed property 
} 
相关问题