WPF - 2.基于Winform模式开发

发布一下 0 0

摘要

WPF 是否可以像传统WinForm一样开发呢?答案是可以的,不过我想没人愿意这么开发吧!

主要是修改启动路径。

正文

WPF启动设置

WPF - 2.基于Winform模式开发

我们像Winform一样创建一个Program的启动类。

我们先创建一个新的Window窗口

internal class Program:Application{    [STAThread]    static void Main()    {        Window1 window1 = new Window1();        Program app=new Program();        app.MainWindow = window1;        app.MainWindow.ShowDialog();    }}

这时运行出现错误,因为有两个启动项

Severity Code Description Project File Line Suppression State Error CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

WPF - 2.基于Winform模式开发

修改一个Window1.xaml.cs文件

public Window1(){    //InitializeComponent();    this.Title = "Hello World";    this.Width = 300;    this.Height = 300;    DockPanel dockPanel= new DockPanel();    Button button1 = new Button();    button1.Content = "Click Me";    button1.Click += Button1_Click;    button1.Margin=new Thickness(20);    button1.Background = new SolidColorBrush(Colors.Green);    IAddChild box = dockPanel;    box.AddChild(button1);//添加按钮到容器    this.Content = box;}private void Button1_Click(object sender, RoutedEventArgs e){    MessageBox.Show("Say Hello");}
WPF - 2.基于Winform模式开发

版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除

本文地址:http://0561fc.cn/99639.html