【发布时间】:2014-12-21 03:43:17
【问题描述】:
我有一个可用的 MouseLeftButtonUp 绑定,我在 View.cs 中工作,但我无法在 Viewmodel.cs 中工作
XAML:
<DataGrid x:Name="PersonDataGrid" AutoGenerateColumns="False"
SelectionMode="Single" SelectionUnit ="FullRow" ItemsSource="{Binding Person}"
SelectedItem="{Binding SelectedPerson}"
MouseLeftButtonUp="{Binding PersonDataGrid_CellClicked}" >
View.cs:
private void PersonDataGrid_CellClicked(object sender, MouseButtonEventArgs e)
{
if (SelectedPerson == null)
return;
this.NavigationService.Navigate(new PersonProfile(SelectedPerson));
}
PersonDataGrid_CellClicked 方法在 ViewModel.cs 中不起作用。我已尝试阅读有关 Blend System.Windows.Interactivity 的信息,但没有尝试过,因为我想在仍在学习 MVVM 时避免它。
我尝试了 DependencyProperty 并尝试了 RelativeSource 绑定,但无法让 PersonDataGrid_CellClicked 导航到 PersonProfile UserControl。
【问题讨论】:
标签: c# wpf mvvm datagrid mouseclick-event