Skip to content

Knowing what ViewModel I was Navigated from #3137

Answered by dansiegel
munkii asked this question in .NET MAUI
Discussion options

You must be logged in to vote

It would seem to me that this is just a tight coupling and bad design. Your ViewModel should only care about the state that it is either passed via NavigationParameters or via services that you may have.

For example:

public class SettingsViewModel(IAppSettings settings)
{
    void DoFoo()
    {
        if (settings.AccountConnected)
        {
            // Do something...
        }
        else
        {
            // Do something else...
        }
    }

    public void OnNavigatedTo(INavigationParameters parameters)
    {
        if (paramters.TryGetValue<bool>("accountConnected", out var accountConnected) && accountConnected)
        {
            // Do something...
        }
        e…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@munkii
Comment options

@dansiegel
Comment options

@munkii
Comment options

@dansiegel
Comment options

Answer selected by munkii
@munkii
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants