This is a migrated thread and some comments may be shown as answers.

Preview (and stop) SelectionChanged

4 Answers 622 Views
NavigationView (Hamburger Menu)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 27 May 2019, 10:35 AM

Hi

Is there a way to Preview the SelectionChanged, and also stop the Navigation.

 

Something like " PreviewSelectionChanged" on RadTabControl, where I can set "Handled=true" to stop navigation.

 

/Peter

 

 

4 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 28 May 2019, 08:06 AM
Hello Peter,

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.
0
Randy
Top achievements
Rank 1
Veteran
answered on 27 Jul 2020, 11:00 AM

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

0
Martin Ivanov
Telerik team
answered on 30 Jul 2020, 10:58 AM

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

0
Randy
Top achievements
Rank 1
Veteran
answered on 31 Jul 2020, 04:23 AM

Hi Martin,

It works perfectly. Thank you for the guidance.

Thanks,

Randy

Tags
NavigationView (Hamburger Menu)
Asked by
Peter
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Randy
Top achievements
Rank 1
Veteran
Share this question
or