Reputation: 3502
I am trying to navigate form one page to another page depends upon the login.
If already user logged in, Welcome page should open. Else Log in Page should open.
I am trying like this. The Splash Page is the start up page.
This is a Splash Screen Xaml.cs:
namespace NewExample.Views
{
public partial class SplashPage : PhoneApplicationPage
{
public SplashPage()
{
InitializeComponent();
this.DataContext = new SplashPageViewModel();
}
}
}
This is Splash Screen View Model: Here I am check the user already logged in or not.
namespace NewExample.ViewModel
{
public class SplashPageViewModel
{
public static bool isLogin = false;
public SplashPageViewModel()
{
var rootFrame = (App.Current as App).RootFrame;
if (isLogin)
rootFrame.Navigate(new Uri("/Views/WelcomePage.xaml", UriKind.Relative));
else
rootFrame.Navigate(new Uri("/Views/LoginPage.xaml", UriKind.Relative));
}
}
}
But it is not working. The Splash Page only showing. This is not navigating to another page. Please help me to resolve this problem.
If I write the codes in Splash Page Xaml.cs, it's working.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
var rootFrame = (App.Current as App).RootFrame;
if (isLogin)
rootFrame.Navigate(new Uri("/Views/WelcomePage.xaml", UriKind.Relative));
else
rootFrame.Navigate(new Uri("/Views/LoginPage.xaml", UriKind.Relative));
}
But I want to use this in ViewModel
.
Upvotes: 0
Views: 68
Reputation: 805
If I understand right what you're trying to accomplish - here is a complete guide at nokia.developer portal.
And if you want to perform UI actions from a ViewModel wrap them with the call to Dispatcher.BeginInvoke .
Upvotes: 1