2012-01-18 40 views
1

我在窗口上有一個帶有DataGrid的WPF/MVVM應用程序。我想在用戶雙擊DataGrid中的一行時調用方法。在DataGrid中捕獲DoubleClick

如何將DataGrid的DblClick事件綁定到ViewModel?

+0

看到此信息[WPF/MVVM - 如何處理雙擊在ViewModel的TreeViewItems?](http://stackoverflow.com/questions/4497825/wpf-mvvm-how-to-handle-double-click-on-treeviewitems-in-the-viewmodel/4498006#4498006) – sll 2012-01-18 19:02:09

+0

謝謝爲鏈接。我喜歡使用CodeBehind鏈接到編輯命令的最後一個解決方案。更簡單的解決方案。 – Jerry 2012-01-19 18:42:57

回答

2

我更喜歡使用AttachedCommand Behaviors,它允許你連接一個命令到幾乎所有UI事件

例如,

<Style TargetType="{x:Type DataGridCell}"> 
    <Setter Property="local:CommandBehavior.Event" Value="MouseDoubleClick" /> 
    <Setter Property="local:CommandBehavior.Command" Value="{Binding MyDoubleClickCommand" /> 
    <Setter Property="local:CommandBehavior.CommandParameter" Value="{Binding }" /> 
</Style>