zoukankan      html  css  js  c++  java
  • 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>

    谢谢.

  • 相关阅读:
    18.AutoMapper 之条件映射(Conditional Mapping)
    17.AutoMapper 之配置(Configuration)
    16.AutoMapper 之可查询扩展(Queryable Extensions)
    15. AutoMapper 之映射继承(Mapping Inheritance)
    14.AutoMapper 之依赖注入(Dependency Injection)
    13.AutoMapper 之映射前后(Before and After Map Action)
    12.AutoMapper 之Null替换(NullSubstitution)
    Windows 2012 系统汉化
    网站反屏蔽常见的六大方法
    Windows系统 本地文件如何复制到远程服务器
  • 原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/11582988.html
Copyright © 2011-2022 走看看