Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row click event in WPF datagrid using mvvm

Tags:

c#

mvvm

wpf

When I click on a row of WPF datagrid, I want to open a new Window that has information about a person from the clicked row (that can be changed) by using binding. How can I do it? And how can I save the changed information?

Thanks in Advance!

like image 603
alex Avatar asked Nov 19 '25 04:11

alex


1 Answers

I did solve a simelar propblem using the Behaviours Libary. First Make sure you have the Nuget package: "Microsoft.Xaml.Behaviors.Wpf" installed.

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

<DataGrid>
    <i:Interaction.Triggers>
        <i:EventTrigger
            EventName="MouseUp">
            <i:InvokeCommandAction
                Command="{Binding OpenWindowCommand}"
                CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}, Path=SelectedItem}">
            </i:InvokeCommandAction>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</DataGrid>

Hope this snippet helps.

like image 54
ChainsawHeadSquirrel Avatar answered Nov 21 '25 19:11

ChainsawHeadSquirrel