VisualStateManager.GoToState在OnNavigatedTo方法中返回false

时间:2012-12-10 10:30:42

标签: c# windows-8 microsoft-metro

它在OnNavigatedTo中不起作用,但在OnNavigatedTo完成后可以正常工作。

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);
}

知道OnNavigatedTo中有什么问题我尝试设置不同的状态,但他们都给了我相同的结果。

我想在OnNavigatedTo方法中或在显示视图之前设置初始状态

1 个答案:

答案 0 :(得分:2)

我已经在Loaded事件中编写了这段代码并且它正在运行。

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);
}