我已经习惯了WinForms,所以这并不是我期望的那样。在下面的代码中,ActiveView是一个框架,寄存器是页面。我想将注册页面加载到ActiveView中,然后更改按钮上的文本。即使页面加载,调试器也会显示SetCloseButtonText中的ActiveView.Content == null。为什么会这样呢?
private void btnRegister_Click(object sender, RoutedEventArgs e)
{
SwapActiveView(Register);
}
public void SwapActiveView(Page NewPage)
{
if (ActiveView.Content == null || !ActiveView.Content.Equals(NewPage))
{
if (ActiveView.Content != null)
{
PreviousViews.Add((Page)ActiveView.Content);
}
ActiveView.Content = NewPage;
}
else
{
ActiveView.Content = NewPage;
}
SetCloseButtonText();
}
private void SetCloseButtonText()
{
if (PreviousViews.Count == 0 && ActiveView.Content == null)
{
tbCloseButton.Text = "Close";
}
else
{
tbCloseButton.Text = "Back";
}
}发布于 2017-03-07 09:52:20
我最终找到了答案。无论您是调用导航函数还是仅更改内容,框架都会异步导航。所以我只需要添加方法,然后调用我的函数。
private void ActiveView_Navigated(object sender, NavigationEventArgs e)
{
SetCloseButtonText();
}https://stackoverflow.com/questions/42637331
复制相似问题