1

我在 WPF 中有一个 DataGrid,其中包含姓名和电子邮件地址列表,以及一个在双击行时执行操作的事件处理程序:

<DataGrid x:Name="DataGrid_Emails" ItemsSource="{Binding AddressBook}">
    <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <EventSetter Event="MouseDoubleClick" Handler="DataGrid_Emails_RowDoubleClick"/>
        </Style>
    </DataGrid.RowStyle>
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"></DataGridTextColumn>
        <DataGridTextColumn Header="Email" Binding="{Binding Path=Email}"></DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

如果选择了多行,我希望能够扩展此功能以处理多行。我是否可以简单地在我的 EventSetter 中添加一些东西来涵盖这种情况?

4

1 回答 1

1

我不认为您可以为此添加任何内容,因为您一次只能双击一行。但是您可以在处理程序中获取 Selected Rows 并将您的操作应用于它们。为此,在您的处理程序中,您可以使用DataGrid 的SelectedItems属性。

于 2013-08-19T04:04:23.490 回答