一双击后获取一行信息 [英] Getting row information after a doubleclick

查看:127
本文介绍了一双击后获取一行信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从一个DataGrid行信息双击事件之后。我有事件设置,但现在我只是需要设置函数从该行检索数据。

I am trying to retrieve row info from a datagrid after a double click event. I have the event setup, but now I just need to setup the function to retrieve the data from the row.

XAML:

    <DataGrid 
        Width="Auto" 
        SelectionMode="Extended" 
        IsReadOnly="True" 
        Name="ListDataGrid"
        AutoGenerateColumns="False"
        ItemsSource="{Binding ListFieldObject.MoviesList}"
        DataContext="{StaticResource MovieAppViewModel}"
        cal:Message.Attach="[Event MouseDoubleClick] = [Action RowSelect()]">

        <DataGrid.Columns>
            <DataGridTextColumn Width="200" IsReadOnly="True" Header="Title" Binding="{Binding Title}"/>
            <DataGridTextColumn Width="100" IsReadOnly="True" Header="Rating" Binding="{Binding Rating}"/>
            <DataGridTextColumn Width="100" IsReadOnly="True" Header="Stars" Binding="{Binding Stars}"/>
            <DataGridTextColumn Width="93" IsReadOnly="True" Header="Release Year" Binding="{Binding ReleaseYear}"/>
        </DataGrid.Columns>
    </DataGrid>

C#(MVVM视图模型):

C# (MVVM ViewModel):

     public void RowSelect()
     {
         //now how to access the selected row after the double click event?
     }

谢谢了!

推荐答案

通过卡利这是很容易,只要通过$的DataContext你的XAML:

With Caliburn it is very easy, just pass $dataContext on your XAML:

 cal:Message.Attach="[Event MouseDoubleClick] = [Action RowSelect($dataContext)]">

和改变你的方法:

public void RowSelect(MoviesListItem movie)
{
     //now how to access the selected row after the double click event?
}

//修改 对不起,您的解决方案只会工作,如果该行为是对的DataTemplate本身......另一种解决办法是有一个的SelectedItem绑定,只是用它在你的方法:

//EDIT Sorry, the above solution will work only if the action is on the datatemplate itself... another solution would be to have a SelectedItem bind and just use it on your method:

<DataGrid 
    SelectedItem="{Binding SelectedMovie,Mode=TwoWay}"
    cal:Message.Attach="[Event MouseDoubleClick] = [Action RowSelect()]">

和你的code:

public void RowSelect()
{
   //SelectedMovie is the item where the user double-cliked
}

这篇关于一双击后获取一行信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆