zoukankan      html  css  js  c++  java
  • WPF 窗体程序入口简介

    1,直接指定StartupUri为某一个window的子类Window1.xaml(属性指定法)

    <Application x:Class="brush.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Window1.xaml">2,通过Startup来指定当前隐藏CS代码的类(brush.App类)的一个方法 MyApplication_Startup(事件指定法)

    <Application x:Class="brush.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Startup="MyApplication_Startup" >上面两种方法都用到了App.xaml(前台表现) 及App.xaml.cs (后台实现),这就是一个Application的实例, 事实上在程序进入入口时已

    启动了Application实例。如果同时指定StartupUri及Startup,不会发生编译错误,但会打开两个窗口。

     3.在后台编辑StartupUri及Startup

    如,在InitializeComponent()方法中,设置了StartupUri属性:

    this.Startup += new System.Windows.StartupEventHandler(this.Application_Startup);
      this.StartupUri = new System.Uri("Window1.xaml",   System.UriKind.Relative);

    它是对App.xaml中的Startup="Application_Startup”和StartupUri="Window1.xaml"翻译。

    4.在入口函数里改

    app.xaml中x:Class属性把xaml所对应的后台C#类联系起来,在这里是WpfApplication1.App,其中App是类名,WpfApplication1是命名空间。App.xaml在编译后产生一个部分类,它位于所创建的项目目录下的obj\Debug子目录中,文件名为App.g.cs。这个文件中的内容如下:

    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Media.Effects;
    using System.Windows.Media.Imaging;
    using System.Windows.Media.Media3D;
    using System.Windows.Media.TextFormatting;
    using System.Windows.Navigation;
    using System.Windows.Shapes;


    namespace WpfApplication1 {
       
       
        /// <summary>
        /// App
        /// </summary>
        public partial class App : System.Windows.Application {
           
            /// <summary>
            /// Application Entry Point.
            /// </summary>
            [System.STAThreadAttribute()]
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public static void Main() {
                WpfApplication2.App app = new WpfApplication1.App();
                app.Run();
            }
        }
    }
    可在Main函数里面修改启动项。注意,app里面只能存在一个程序入口函数,即这里的Main函数,否则会编译错误。当然,你也完全可以把App.g.cs里面的Main函数移到App.xaml.cs文件里面,因为他们都是部分类。这样就可以通过入口函数来修改启动窗体。

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/a0700746/archive/2010/04/18/5499450.aspx

  • 相关阅读:
    eclipse luna maven失效的原因
    利用线性探测法解决hash冲突
    PHP和JavaScript将字符串转换为数字string2int
    JavaScript 编程易错点整理
    使用phpstudy创建本地虚拟主机
    单例模式
    PHP使用cookie时遇到的坑
    Redis安装与配置
    CI框架2.x的验证码中所遇问题解决
    用delete和trancate删除表记录的区别
  • 原文地址:https://www.cnblogs.com/elaborateday/p/1865843.html
Copyright © 2011-2022 走看看