To keep track of the last comment (can I give a link to a specific comment?) I will write another answer so that people can follow.
I think that you do not have enough event points. What do you want your event handler to know when it received it? This, as a rule, is the purpose of the event arguments - you pass some information to the handler, with which you give some idea of what exactly happened.
So, the first time you raise your event, you will do it like this:
private void lstvMyView_SelectionChanged(object sender, SelectionChangedEventArgs e) { SelectionChangedEventArgs args = new SelectionChangedEventArgs(SelectedEvent, e.RemovedItems, e.AddedItems); RaiseEvent(args); }
First you need to build the arguments, and then use the RaiseEvent() function with these arguments, because you want to raise a special type of wpf routing. The arguments must be an instance of a class that inherits RoutedEventArgs. Note that you create SelectionChangedEventArgs , which are defined in wpf, to “transfer” additional information to the event handler - namely, which elements were removed from the selection and which were added, so when the handler receives the event, it can use this information. if he wants to. You think about it:
//Normal Event Raise if (Selected != null) Selected(this, e);
basically - (as I said in my first answer) delete it, you don't need it.
So, what bothers you, the second time you raise an event. This is a prototype of what you need to do:
private void lstvMyView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { SelectionChangedEventArgs args = new SelectionChangedEventArgs(SelectedEvent, ?, ?); RaiseEvent(args); }
as you see, again you need to build SelectionChangedEventArgs and use the RaiseEvent() function to raise the event. But this time, you cannot use e.RemovedItems and e.AddedItems , because you are handling the MouseLeftButtonUp event, which (through its args) carries information about the state of the mouse - not that the elements were added to the selection (in the end, its event mouse, not a selection event). You must decide what to replace the two question marks with - as I said in the comments to the first answer, you need to decide what information you want to convey to the user of your event. What does it mean that the mouse button is no longer on "lstvMyView"? The easiest way to do the following:
SelectionChangedEventArgs args = new SelectionChangedEventArgs(SelectedEvent, Enumerable.Empty<object>(), Enumerable.Empty<object>()); RaiseEvent(args);
with which you raise an event and tell your consumer that no items have been removed from the selection and no items have been added.