gpt4 book ai didi

c# - 双击后获取行信息

转载 作者:太空狗 更新时间:2023-10-29 17:29:47 25 4
gpt4 key购买 nike

我试图在双击事件后从数据网格中检索行信息。我有事件设置,但现在我只需要设置函数来从行中检索数据。

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 View 模型):

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

非常感谢!

最佳答案

您也可以这样做:

<DataGrid>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="cal:Message.Attach" Value="[MouseDoubleClick] = [Action RowSelect($dataContext)]"/>
</Style>
</DataGrid.RowStyle>
</DataGrid>

然后

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

关于c# - 双击后获取行信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9487084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com