Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF DataGrid对多个选定行执行操作_C#_Wpf_Xaml_Events_Datagrid - Fatal编程技术网

C# WPF DataGrid对多个选定行执行操作

C# WPF DataGrid对多个选定行执行操作,c#,wpf,xaml,events,datagrid,C#,Wpf,Xaml,Events,Datagrid,我在WPF中有一个DataGrid,其中包含一个名称和电子邮件地址列表,还有一个事件处理程序,在双击某行时执行操作: <DataGrid x:Name="DataGrid_Emails" ItemsSource="{Binding AddressBook}"> <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <EventSetter

我在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中添加一些内容来涵盖此场景?

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

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

谢谢!我的问题可能措辞有点含糊,但我能用SelectedItems让它起作用。我只是将我的操作绑定到回车键:)谢谢!我的问题可能措辞有点含糊,但我能用SelectedItems让它起作用。我只是将我的操作绑定到Enter键:)