【问题标题】:How to navigate from a pop-up dialog window to another page in wpf i'm not using MVVM如何从弹出对话框窗口导航到 wpf 中的另一个页面我没有使用 MVVM
【发布时间】:2017-09-28 15:15:16
【问题描述】:

当用户从 WPF 对话窗口中选择一个选项时,我想导航到另一个页面。从第 1 页,我通过按钮单击事件弹出带有此代码的窗口

private void newCust_Click(object sender, RoutedEventArgs e)
    {
        bvnQuery bv = new bvnQuery();
        bool? val = bv.ShowDialog();

        if (val.HasValue && val.Value)
        {
            NavigationService.Navigate("page3.xaml", UriKind.Relative);
        }
    }

然后在对话框窗口上,我选择了一个是/否选项(按钮),当我将值返回给调用函数时,当我导航到上面 URI 中的页面时,我得到一个空白页面。我该如何解决这个问题?

【问题讨论】:

  • 你在使用 NavigationService 吗?
  • 是的,我正在使用这个 NavigationService.Navigate("page3.xaml", UriKind.Relative);但它没有导航到页面
  • 尝试将导航服务添加到您的按钮单击方法中?
  • @AGrammerPro 我已经做到了
  • 不确定你是否已经检查过,所以我会发布它stackoverflow.com/questions/20787622/…

标签: c# wpf wpf-controls


【解决方案1】:

您应该在“是/否”处理程序中设置bvnQuery 窗口的DialogResult 属性:

private void Button_Click(object sender, RoutedEventArgs e)
{
    this.DialogResult = true;
}

此值将从ShowDialog() 方法返回:

private void Button_Click(object sender, RoutedEventArgs e)
{
    bvnQuery bv = new bvnQuery();
    bool? val = bv.ShowDialog();

    if (val.HasValue && val.Value)
    {
        //...
    }
}

【讨论】:

  • 当我执行此操作时,它没有导航到所需的页面 NavigationService.Navigate("page3.xaml", UriKind.Relative);在 if 块内。 val 返回真
  • 我已经用您提供的代码示例更新了我的问题。谢谢
  • 我的错。我很抱歉造成混乱。你说得对,我应该这样做 NavigationService.Navigate(new Uri("page3.xaml", UriKind.Relative));。谢谢
猜你喜欢
  • 2012-06-22
  • 1970-01-01
  • 2022-01-13
  • 2014-04-27
  • 2018-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-08
相关资源
最近更新 更多