简体   繁体   中英

WPF DataGrid perform action on multiple selected rows

I have a DataGrid in WPF that contains a list of names and email addresses, and an event handler that performs an action when a row is double-clicked:

<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>

I'd like to be able to extend this functionality to work on multiple rows if multiple rows are selected. Is it possible for me to simply add somethins to my EventSetter to cover this scenario?

I dont think you can add anything to this because you can doubleclick only one row at a time. But you can get the Selected Rows in your handler and apply your action to them. For that In your handler you can use SelectedItems property of DataGrid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM