我已经习惯了WinForms,所以这并不像我期望的那样。在下面的代码中,ActiveView是一个Frame,Register是Page。我想将注册页面加载到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";
}
}
答案 0 :(得分:0)
我最终找到了答案。无论您是调用导航功能还是仅更改内容,帧都会异步导航。所以我只需要添加方法然后调用我的函数。
private void ActiveView_Navigated(object sender, NavigationEventArgs e)
{
SetCloseButtonText();
}