本文介绍了VisualStateManager.GoToState 在 OnNavigatedTo 方法中返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它在 OnNavigatedTo
中不起作用,但它在 OnNavigatedTo
完成后起作用.
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);
}
知道 OnNavigatedTo
有什么问题我尝试设置不同的状态,但它们都给我相同的结果.
Any idea what's wrong in OnNavigatedTo
I tried to set different states but they all are giving me same result.
我想在 OnNavigatedTo
方法中或在显示视图之前设置初始状态
I want to set the initial state in OnNavigatedTo
method or before view is shown
推荐答案
我已经在 Loaded 事件中编写了这段代码并且它正在工作.
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);
}
这篇关于VisualStateManager.GoToState 在 OnNavigatedTo 方法中返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!