Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40018

VisualStateManager.GoToState returns false in OnNavigatedTo method

It's not working in OnNavigatedTo but it works after OnNavigatedTo finishes.

protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    //Here result is false
    bool result = VisualStateManager.GoToState(btn_reset, "Normal", false);
}


private void Button_Click(object sender, RoutedEventArgs e)
{
   //Here result is true
  bool result = VisualStateManager.GoToState(btn_reset, "Normal", false);
}

Any idea what's wrong in OnNavigatedTo I tried to set different states but they all are giving me same result.

I want to set the initial state in OnNavigatedTo method or before view is shown

Upvotes: 2

Views: 814

Answers (1)

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40018

I have written this code in Loaded event and it's working.

protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    Loaded += ScreenLoaded;
}

private void ScreenLoaded(object sender, RoutedEventArgs e)
{
    btn_reset.IsEnabled = false;
    bool result = VisualStateManager.GoToState(btn_reset, "Normal", false);
}

Upvotes: 2

Related Questions