【发布时间】:2012-03-18 05:28:56
【问题描述】:
我试图在双击事件后从数据网格中检索行信息。我有事件设置,但现在我只需要设置函数来从行中检索数据。
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 视图模型):
public void RowSelect()
{
//now how to access the selected row after the double click event?
}
非常感谢!
【问题讨论】:
-
据我所知,即使不是不可能,也非常困难。很多网站都在讨论这个问题,例如scottlogic.co.uk/blog/colin/2008/12/… 和这个stackoverflow.com/questions/5808616/…
标签: c# .net xaml mvvm caliburn.micro