4 Answers, 1 is accepted
The selection API of RadNavigationView doesn't allow canceling the selection. However, you can use the PreviewMouseLeftButtonDown event of the control in order to prevent it. Here is an example in code:
private
void
RadNavigationView_PreviewMouseLeftButtonDown(
object
sender, System.Windows.Input.MouseButtonEventArgs e)
{
var item = e.Source
as
RadNavigationViewItem;
if
(item !=
null
&& item.Content.Equals(
"Item 1"
))
{
e.Handled =
true
;
}
}
If you populate the control via data binding (setting ItemsSource), you can implement the selection canceling in the setter of the SelectedItem property. You can see this approach in the attached project.
I hope this helps.
Regards,
Martin Ivanov
Progress TelerikWant to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.

Hi Martin,
I used a behavior to handle the PreviewMouseLeftButtonDown event, the logic works as expected. A confirmation dialog is used during the preview event so the user could confirm if he want to cancel or not. When he selects continue and e.Handled is set to false, the selection continues and the new target item is selected with a "selected" style. Otherwise e.Handled=True and the selection is cancelled. So far all make sense.
However, since I'm using Fluent theme, there's a shiny rectangular at the left part of the selected item. When e.Handled=false, though the new target item has the selected style (grey background), that shiny rectangulart stays with the old selected item. This looks a little bizarre since the grey background and the rectangular are at different items. I tried to not showing the confirmation dialog and the rectangular refreshes to the new selected item, so I guess it's sth about the focus changing and the rectangular master does not refresh because the focus changed to the dialog.
Is there any way to fix this? Though most other themes seem not have this issue but Fluent theme is the better option here.
Thanks,
Randy
Hello Randy,
This happens because parts of the visual states of the items rely on the mouse events. However, when you open a dialog, the events are capture by it and some of the states cannot be properly executed. To avoid this, you can manually update the item when the dialog closes. If the Handled is set to True, you can hide the hover background by setting the IsHighlighted property of the item to false and if it is False, you can manually select the item using its IsSelected property.
For example:
var r = MessageBox.Show("handle?", "handle?", MessageBoxButton.YesNo);
if (r == MessageBoxResult.Yes) { item.IsHighlighted = false; e.Handled = true; } else { item.IsSelected = true; e.Handled = false; }
Regards,
Martin Ivanov
Progress Telerik

Hi Martin,
It works perfectly. Thank you for the guidance.
Thanks,
Randy