Repository navigation
Replies: 2 comments 3 replies
|
I was able to use CommunityToolKit.MVVM.Messaging so each viewmodel can send a message to the MainWindowViewModel when it's busy and wants to block navigation. MainWindowViewModel will then set its CanNavigate property to false. My MainWindow code behind wires to the RootNavigation_Navigating event:
Has anyone got a suggestion to improve this? Thanks! |
|
@gleclair This doesn't address your original problem, just a modification of your event handler solution using styles instead. This disables the navigation buttons, so the navigation should be fully cancelled. I still rely on IMessenger for the page viewmodel to communicate with MainWindow viewmodel . Put this inside <ui:NavigationView.Resources>
<Style TargetType="{x:Type ui:NavigationViewItem}" BasedOn="{StaticResource NavigationViewItemDefaultStyle}">
<Setter Property="IsEnabled" Value="{Binding ViewModel.CanNavigate, Mode=OneWay}" />
</Style>
</ui:NavigationView.Resources> |
Uh oh!
There was an error while loading. Please reload this page.
First off, many thanks to @pomianowski and other contributors for creating and maintaining this solution, your work is very much appreciated!!
My question is: Is there a way for a view model to disable or cancel navigation? If a user is in the middle of editing, I want them to either save or discard changes before moving to another screen. Maybe I could disable the navigation menu when editing starts, or wire into an event to cancel it? Hopefully I'm missing something easy, any suggestions are appreciated.
All reactions