Silverlight 3 Beta, NavigationService in ViewModel

im developing a silverlight 3 beta navigation app, so I went with a little modification to the MVVM template :) (all-in-one viewing model) using a prism, etc.

Question: How to switch to another "NavigationPage" in view mode

Now, to shorten the long story, the viewmodel is declared as a page resource.

<navigation:Page.Resources>
    <mvvm:LoginModel x:Key="DataSource" d:IsDataSource="True"></mvvm:LoginModel>
</navigation:Page.Resources>

And then the command is used to connect everything using viewmodel

<Button x:Name="LoginButton" Width="100"  Margin="8" Content="Login"
        prism:Click.Command="{Binding LoginCommand}"/>

Now, if I try to navigate anywhere in the viewmodel, so

this.NavigationService.Navigate(new Uri("/Views/About.xaml", UriKind.Relative));

Navigationservice null, , helix 0.3 , sl2-, , , , INavigationAware viewmodel, NavigationContext, , , helix, .

SL3 , , , . , sl3.

- SL3, helix INavigationAware?

+3
5

, NavigationService - UI-, .

, NavigationService , , ViewModel , ... Navigate .

+4

, , , . OnNavigatedTo ViewModel NavigationService viewmodel, viewmodel

    protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ViewModels.LoginViewModel viewmodel = (ViewModels.LoginViewModel)this.Resources["DataSource"];
//DataSource being the x:Name given to the viewmodel that is loaded as a page resource
            viewmodel .service = NavigationService;
        }
+1

, , MVVM. , , .

+1

In order to help my question, because there was still no answer, I am going to tell more about it.

This is the code in viewmodel

public LoginModel()
    {
        LoginCommand = new DelegateCommand<object>(LoginCommandExecuted, a => { return _CanLoginCommandExecute; });
    }

    public ICommand LoginCommand { get; private set; }
    private bool _CanLoginCommandExecute = true;
    private void LoginCommandExecuted(object parameter)

    {
        _CanLoginCommandExecute = false;

        AdminClient client = new AdminClient();
        client.AuthorizeAsync();
        client.AuthorizeCompleted += 
        new EventHandler<AsyncCompletedEventArgs>(
                (s, e) =>
                {
                    if (e.Error != null)
                    {
                        MessageBox.Show("Login Failed");
                    }
                    else
                    {
                        this.NavigationService.Navigate(new Uri("/Views/About.xaml", UriKind.Relative));
                    }
                    _CanLoginCommandExecute = true;
                }
                );

    }

NavigationService is null, so I cannot go to the next view, help !!!

0
source
NavigationService.Navigate(new Uri("/About", UriKind.Relative));

Above should work.

0
source

Source: https://habr.com/ru/post/1711154/