Creating an instance of SelectionChangedEventArgs in wpf

I have a user control that has a list in it. The SelectionChanged event of this list view is handled internally by the user control. The code for it is as follows:

        private void lstvMyView_SelectionChanged (object sender, SelectionChangedEventArgs e)
        {...}

I want to call this handler again from another place inside the user control. Therefore, to call this handler, I need "SelectionChangedEventArgs". When I try to create an instance of "SelectionChangedEventArgs", I cannot understand what I should pass as the parameters to the constructor of "SelectionChangedEventArgs".

The place where I should call this handler does not add or remove any items in the list. It simply moves around in the list items, thereby changing the selected list index.

I am trying to do something like this. Invalid code below.

lstvMyView_SelectionChanged (_lstvMyView, new SelectionChangedEventArgs ());
+4
source share
2 answers

I want to call this handler again from another place inside the user control

Do not . An event handler should not be called explicitly from your code. No matter what you do in this handler, you can put it in another method that takes only the necessary parameters and call the method thatfrom your code.

+2

SelectionChangedEventArgs :

new SelectionChangedEventArgs(
    System.Windows.Controls.Primitives.Selector.SelectionChangedEvent, 
    new List<CustomViewModel> { }, 
    new List<CustomViewModel> { customViewModel }
)

, removedItems addedItems , .

0

Source: https://habr.com/ru/post/1767129/


All Articles