码迷,mamicode.com
首页 > Windows程序 > 详细

WPF中DataGrid双击命令获取选中的ViewModel

时间:2016-02-15 18:26:55      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:

xaml

<DataGrid  x:Name="myGrd"
          ItemsSource="{Binding SearchItems}"
          SelectedItem="{Binding SelectedItem}"
          SelectionMode="Single"
          SelectionUnit="FullRow">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <cmd:EventToCommand Command="{Binding MouseDoubleClickCommand}"  
                                CommandParameter="{Binding ElementName=myGrd, Path=SelectedItem}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    ...
</DataGrid>

ViewModel

public ICommand MouseDoubleClickCommand
{
    get
    {
        if (mouseDoubleClickCommand == null)
        {
            mouseDoubleClickCommand = new RelayCommand<SearchItem>(
                item =>
                {
                    var selectedetitem = item;
                }
                );
        }
        return mouseDoubleClickCommand;
    }
}

 

WPF中DataGrid双击命令获取选中的ViewModel

标签:

原文地址:http://www.cnblogs.com/saybookcat/p/5190892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!