zoukankan      html  css  js  c++  java
  • 《Applications=Code+Markup》读书札记(1)——一个简单的 WPF 程序

    笔者开发环境是 Windows 7 旗舰版 + .Net Framework 4 + Visual Studio 2010,以后系列文章都以该环境为基础。

    1、新建一个 Visual C# Windows 空项目,其实没有别的目的,就是为了弄清楚 WPF 所依赖的程序集;

    2、构建一个简单的 WPF 应用程序必须引用 PresentationCore、PresentationFramework、System、System.Xaml、WindowsBase 等程序集;

    3、给项目 WpfAppByCode 添加一个“类”项,将该文件里系统默认生成的代码全部删除,加入 System 和 System.Windows 这两个命名空间。如果你不熟悉 System 命名空间,我不解释。System.Windows 这个命名空间包含了所有的 WPF 类别、结构(struct)、接口(interfce)、委托(delegate),以及枚举类型(enum),当然也包括了 Application 和 Window 这两个类。其他的 WPF 命名空间均以 System.Windows 开头,例如 System.Windows.Controls、System.Windows.Input、System.Windows.Media。只有 System.Windows.Forms 是个例外,它主要是 Windows.Forms 的命名空间。除了 System.Windows.Forms.Integration 这个命名空间里的类是用来集成 Windows.Forms 和 WPF 程序的,其他所有以 System.Windows.Forms 开头的命名空间,都是属于传统的 Windows.Forms 命名空间。

    using System;
    using System.Windows;

    namespace WpfAppByCode
    {
    class Program
    {
    [STAThread]
    public static void Main()
    {
    Window mMain
    = new Window();
    mMain.Title
    = "稻草人";
    mMain.Show();
    System.Windows.Application app
    = new Application();
    app.Run();
    }
    }
    }

    4、以上代码编译运行后,你会发现一个 Console 窗口也在运行。这是源自编译选项的设定,你可以在工程的 属性->应用程序->输出类型 中修改此编译选项:将输出类型改成 Windows 应用程序。笔者认为在开发阶段,Console 窗口其实是相当有用的。程序运行时可以用它来显示一些文本信息,以便调试。如果程序的 Bug 太多,甚至无法将 GUI 窗口显示出来,或者进入无限期循环,这个时候,只要在 Console 窗口键入 Ctrl+C,就可以轻易地关闭程序。这些都是 Console 窗口附带的好处。

  • 相关阅读:
    解决:Could not resolve archetype org.apache.maven.archetypes
    Spring MVC配置MyBatis输出SQL
    Spring集成MyBatis 通用Mapper以及 pagehelper分页插件
    关于SpringMVC或Struts2接受参数接收不到的原因
    配置quartz启动时就执行一次
    ajaxFileUpload进行文件上传时,总是进入error
    spring mvc注入配置文件里的属性
    java中将一个文件夹下所有的文件压缩成一个文件
    flume failed to start agent because dependencies were not found in classpath
    ubuntu不能安装pip unable to install pip in unbuntu
  • 原文地址:https://www.cnblogs.com/daocaoren/p/2082222.html
Copyright © 2011-2022 走看看