WPF APP 启动时增加特殊逻辑

时间:2020-11-08 17:59:30   收藏:0   阅读:30
  public partial class App : Application
    {
        public App()
        {
            this.Startup += (o1, e1)=>{
                string commandLine = Environment.CommandLine;  
                string appFilePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                commandLine = commandLine.Replace(String.Format("\"{0}\" ", appFilePath), ""); 得到命令参数

                MessageBox.Show(string.Format("commandLine:{0}", Environment.CommandLine));
                MessageBox.Show("SpiltResult:" + commandLine);
                if (!string.IsNullOrEmpty(commandLine) && commandLine.ToUpper() == "SA")//启动参数带SA则转到特殊处理页面
                {
                    this.ShutdownMode = ShutdownMode.OnLastWindowClose;  
                    this.StartupUri = new Uri("pack://application:,,,/Views/SNPrint/SA_MODE.xaml");  //
                    MessageBox.Show("Set URI!");
                }
//正常App.xaml中存在StartupUri如【StartupUri="MasterWindow.xaml"】则可以省略下面代码 //else //{ // this.StartupUri = new Uri("pack://application:,,,/MasterWindow.xaml"); // MessageBox.Show("MAIN URI!"); //} }; } }

技术图片

//new Uri("pack://application:,,,/Views/SNPrint/SA_MODE.xaml"); 代表如下

技术图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!