• wpf 在main启动应用程序


    方法一:

     1 using System;
     2 
     3 using System.Collections.Generic;
     4 
     5 using System.Linq;
     6 
     7 using System.Text;
     8 
     9 using System.Threading.Tasks;
    10 
    11 using System.Windows;
    12 
    13 
    14 
    15 namespace WpfApp1
    16 {
    17 
    18     class App
    19     {
    20 
    21         [STAThread]
    22 
    23         static void Main()
    24         {
    25 
    26             // 定义Application对象作为整个应用程序入口  
    27 
    28             Application app = new Application();
    29             //指定Application对象的MainWindow属性为启动窗体,然后调用无参数的Run方法  
    30 
    31             MainWindow win = new MainWindow();
    32 
    33             app.MainWindow = win;
    34 
    35             //是必须的,否则无法显示窗体       
    36 
    37             win.Show();
    38 
    39             app.Run();
    40 
    41         }
    42 
    43     }
    44 }

    方法二:

     1 using System;
     2 
     3 using System.Collections.Generic;
     4 
     5 using System.Linq;
     6 
     7 using System.Text;
     8 
     9 using System.Threading.Tasks;
    10 
    11 using System.Windows;
    12 
    13 
    14 
    15 namespace WpfApp1
    16 {
    17 
    18     class App
    19     {
    20 
    21         [STAThread]
    22 
    23         static void Main()
    24         {
    25 
    26             // 定义Application对象作为整个应用程序入口  
    27 
    28             Application app = new Application();
    29 
    30             // 通过Url的方式启动
    31 
    32             app.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
    33 
    34             app.Run();
    35 
    36         }
    37 
    38     }
    39 
    40 }

    方法三:

     1 using System;
     2 
     3 using System.Collections.Generic;
     4 
     5 using System.Linq;
     6 
     7 using System.Text;
     8 
     9 using System.Threading.Tasks;
    10 
    11 using System.Windows;
    12 
    13 
    14 
    15 namespace WpfApp1
    16 {
    17 
    18     class App
    19     {
    20 
    21         [STAThread]
    22 
    23         static void Main()
    24         {
    25 
    26             // 定义Application对象作为整个应用程序入口  
    27 
    28             Application app = new Application();
    29 
    30             // 方法一:调用Run方法 ,这种方式跟winform的调用一样
    31 
    32             MainWindow win = new MainWindow();
    33 
    34             app.Run(win);
    35         }
    36 
    37     }
    38 
    39 }

    附:

    1 <Window x:Class="WpfApp1.MainWindow"
    2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4         Title="MainWindow" Height="350" Width="555">
    5     <Grid>
    6         
    7     </Grid>
    8 </Window>

    谢谢.

  • 相关阅读:
    Java 编程下的并发线程之间的同步代码块死锁
    Java 编程下的同步代码块
    Android 编程下两种方式注册广播的区别
    Java 编程下泛型的内部原理
    Android 编程下使用 Google 的 Gson 解析 Json
    c# 调用音库开发英语单词记忆本
    在.Net中实现RichClient+Restful+JPA架构探索实现
    Extjs 常用正则式
    企业内IT部门的一些问题总结
    WinServer2003部署VS2010的水晶报表
  • 原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/11582988.html
Copyright © 2020-2023  润新知