我以为只有usercontrol可以在WPF应用程序的窗口框架内导航页面,有没有解决办法?

时间:2017-10-06 10:24:11

标签: c# wpf

如果读取数据失败,我试图跳转到错误页面,虽然我认为只有当usercontrol激活(例如按下按钮)才能成功导航,但无论如何都要自动执行?

Window
|--Page
|--Page
  1. - 页面
  2. - 页面
  3. 代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Xml;
    
    namespace Launcher
    {
        /// <summary>
        /// Interaction logic for BootPage.xaml
        /// </summary>
        public partial class BootPage : Page
        {
            public BootPage()
            {
                InitializeComponent();
                readConfig();
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                bootError(1001); **//This works**
            }
    
            void readConfig()
            {
    
                string gamePath;
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("e:\\bootstrap.xml");
                XmlNodeList boot = xmlDoc.DocumentElement.SelectNodes("/config/startup/arkkdmca/boot");
    
                foreach (XmlNode node in boot)
                {
                    try
                    {
                        gamePath = node.SelectSingleNode("drive").InnerText + ":\\" + node.SelectSingleNode("directory").InnerText;
                        MessageBox.Show(gamePath);
                    }
                    catch(Exception)
                    {
                        gamePath = "null";
                        bootError(1001); **//This Failed**
                        return;
                    }
                }
            }
    
            void bootError(int errorCode)
            {
                this.NavigationService.Navigate(new ErrorPage(errorCode));
            }
        }
    }
    

0 个答案:

没有答案