Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to get the last selected item in WPF Datagrid

$
0
0

I am using a WPF Datagrid and I want to keep a record of which was the last selected item when I do selection changed event but want to cancel the operation if user opts for the same.

For this I used eventargs travel from my Veiw to Viewmodel. Is there any other way ? I wanted to do it in pure MVVM fashion. Relevant code below

<i:Interaction.Triggers>                       

<i:EventTrigger EventName="SelectionChanged">                           

<cal:ActionMessage MethodName="grd_SelectionChanged"  >

<cal:Parameter Value="$eventArgs"/>                        

</cal:ActionMessage>
                     
</i:EventTrigger>

</i:Interaction.Triggers>

In the view model in the event handler

publicasyncvoidgrd_SelectionChanged(SelectionChangedEventArgseventArgs)

{

var previousElement = eventArgs.RemovedItems[0] as ISomeIdName;
                    if (previousElement != null)
                    {
                        SomeIdName = previousElement;
                    }

}


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>