WPF MVVM和行为 - 使用AssociatedObject.DataContext是一种很好的做法

时间:2015-12-18 10:56:31

标签: wpf mvvm

使用WPF行为时 - 使用为AssociatedObject.DataContext定义的ViewModel是一种很好的做法(MVVM方面)吗?就像行为中的这个事件处理程序一样:

    private void Plate_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        UserControl userControl = AssociatedObject as UserControl;
        Border borderParent = userControl.Parent as Border;
        PlateViewModel plateViewModel = userControl.DataContext as PlateViewModel;

        plateViewModel.ElementSelectedItem.Caption = "Selected Item";
    }

0 个答案:

没有答案