当前位置: 移动技术网 > IT编程>开发语言>.net > [Wpf学习] 1.传说中的Main

[Wpf学习] 1.传说中的Main

2020年03月09日  | 移动技术网IT编程  | 我要评论

御宇游,网王将错就错,三洋微波炉怎么样

原来的c#程序都有main的,现在用vs新建一个wpf项目,启动似乎变成app.xmal,前期项目中为了获取启动参数,很是折腾了一番:

1.先是修改app.xaml,添加startup事件

<application x:class="ykmain.app"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:ykmain"
             startup="application_startup">

2.然后编辑application_startup,判断e.args数组

  private async void application_startup(object sender, startupeventargs e)
  {
  }

总感觉跟又臭又长的裹脚布一样,不爽。学习后,找回了传说中的main,莫有app.xaml,直截了当。

using system;
using system.windows;

namespace l1_noxaml
{
    public class program : application
    {
        [stathread]
        static void main(string[] args)
        {
            program app = new program();
            app.mainwindow = new window1();
            app.mainwindow.showdialog();
        }
    }
}

ps:2020/3/3完善了一下

using system;
using system.windows;

namespace ykmaincore
{
    public class program : application
    {
        [stathread]
        static void main(string[] args)
        {
            splashscreen splashscreen = new splashscreen("id.png");
            splashscreen.show(true);

            mainwindow window = new mainwindow()
            {
                windowstyle = windowstyle.none,
                resizemode = resizemode.noresize,
                windowstate = windowstate.normal,
                showintaskbar = false,
                background = system.windows.media.brushes.transparent,
                allowstransparency = true,
                left = 0,
                top = 0,
                width = systemparameters.primaryscreenwidth,
                height = systemparameters.primaryscreenheight
            };

            program app = new program();
            app.run(window);
        }
    }
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网