How to remove an EventHandler?


  • I have a ListView XAML control, where I've registered an event handler for the ListView.SelectionChanged event:

    list->SelectionChanged += ref new Windows::UI::Xaml::Controls::SelectionChangedEventHandler(this, &MyProgram::MainPage::OnListSelectionChanged);
    How do I go about de-registering/removing this event handler?

    Monday, November 7, 2011 8:17 AM


  • auto cookie = list->SelectionChanged += ref new Windows::UI::Xaml::Controls::SelectionChangedEventHandler(this, &MyProgram::MainPage::OnListSelectionChanged);
    list->SelectionChanged -= cookie;

    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Marked as answer by stugreco Tuesday, November 8, 2011 2:48 AM
    Monday, November 7, 2011 8:25 PM