Prevent SelectionItemChanged for RadNavigationView

1 Answer 24 Views
NavigationView (Hamburger Menu)
Kyle
Top achievements
Rank 2
Veteran
Iron
Kyle asked on 31 Mar 2025, 05:25 PM

I was looking at the https://www.telerik.com/forums/preview-(and-stop)-selectionchanged post from 5 years ago. In the first answer, there was an attached solution to the problem. If using the ItemsSource binding, you could prevent the change by not firing the OnPropertyChanged event.

I loaded this project using the 2025Q1 dlls and while the SelectedItem may not technically update, the UI reflects that the item is selected. Is there an updated solution to this?

Kyle
Top achievements
Rank 2
Veteran
Iron
commented on 31 Mar 2025, 06:04 PM

Also, it appears that the other solution (using the PreviewMouseLeftButtonDown event) doesn't work, because e.Source is the RadNavigationView, NOT the RadNavigationViewItem.

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 01 Apr 2025, 06:39 AM

Hello Kyle,

Indeed, the first solution with handling the SelectedItem property of the view model doesn't work very well with RadNavigationView. Instead, you can use the approach with the PreviewMouseLeftButtonDown event. To get the proper RadNavigationViewItem in the event handler when using the ItemSource to populate the control, you can use the OriginalSource of the arguments.

private void RadNavigationView_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    var clickedElement = (FrameworkElement)e.OriginalSource;
    var itemContainer = clickedElement.ParentOfType<RadNavigationViewItem>();
    if (itemContainer != null && ((MyItemInfo)itemContainer.DataContext).Name.Equals("Item 1"))
    {
        e.Handled = true;
    }
}

Regards,
Martin Ivanov
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Kyle
Top achievements
Rank 2
Veteran
Iron
commented on 02 Apr 2025, 02:52 PM

This worked. I sure do wish there were "ing" and "ed" events like in WinForms. :)

Tags
NavigationView (Hamburger Menu)
Asked by
Kyle
Top achievements
Rank 2
Veteran
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or