WPF Application
Application类作为启动的入口,在VS中,通常自动代码为我们继承了Application类,这样做的有点,我还没有理解到,但是我们先学到这个知识点。
为了能够更好的控制整个启动过程,包括得到Active,LoadComplete,Deactive,SessionEnding等事件,可以主动改变程序的入口,即是static void Main(string[] args)方法的所在位置。
我们主动添加一个Program.cs(当然叫别的名字是可以的)的文件,添加Main方法,并在其中修改启动,代码就可以了。说的比较粗略,看代码吧。
Program.cs
using System; namespace LearnWPF
{
class Program
{
[STAThread]
public static void Main(string[] args)
{
App app = new App();
myWInd m = new myWInd();
app.MainWindow = m;
m.Show();
app.Run();
}
}
}
App.xaml.cs
using System;
using System.Diagnostics;
using System.Windows; namespace LearnWPF
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
Debug.WriteLine("OnActived");
} protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
Debug.WriteLine("OnDeactived");
} protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
MessageBox.Show("Exiting");
} protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
{
base.OnSessionEnding(e);
MessageBox.Show("you're quitting");
} protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
MessageBox.Show("Staring");
} protected override void OnLoadCompleted(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnLoadCompleted(e);
MessageBox.Show("completed");
}
}
}
App.xaml 这文件指明了启动的窗口等内容,所以需要相应地修改。
<!--application 的 class属性可以随便写-->
<!--application 的 StartupUri属性指明了 启动的窗体-->
<Application x:Class="muhaha"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources> </Application.Resources>
</Application>
但是,到了这里还是不行的;因为对于App.xaml在自动生成的代码里,会有Main方法入口,因此还需要改变程序的入口,在项目的属性里修改配置。请注意,刚刚添加Program.cs文件后,可能这里不会有,编译一次,就会在这里出现了,如下图所示。

希望能够帮助一些同学。
WPF Application的更多相关文章
- Handling events in an MVVM WPF application
Posted: June 30, 2013 | Filed under: MVVM, WPF, XAML |1 Comment In a WPF application that uses the ...
- 【转】How to view word document in WPF application
How to view word document in WPF application (CSVSTOViewWordInWPF) Introduction The Sample demonstra ...
- Merging a WPF application into a single EXE(WPF应用程序合并成单个Exe文件)
I always dislike handing off little applications to people. Not because I can’t, but because of the ...
- C# WPF Application 下的文件操作
好气哦,电脑好烂,每天花大把的时间在等电脑反应上. 没有钱买新电脑,连组台式机的钱都没有.好气哦. 啊啊啊啊文件操作是什么鬼???C++下我都懵了,C#下好多东西要学!!!我不会!我不会!我不会!!! ...
- 每天翻译一点点: WPF Application Framework (WAF)
ps:http://waf.codeplex.com/wikipage?title=Model-View-ViewModel%20Pattern&referringTitle=Document ...
- WPF Application 类介绍以及怎样修改启动方式
因为想要修改wpf的启动方式,所以研究了下Application类,现把一些有用的属性与大家分享下: 属性: Current 获取当前 AppDomain的 Appl ...
- WPF——Application
Application类处于WPF应用程序的最顶端,main函数就在这个类中. Application类的作用: 截图连接 https://docs.microsoft.com/zh-cn/dotne ...
- vs 编译错误 The name 'InitializeComponent' does not exist in the current context in WPF application
1:文件命名空间的问题 xaml文件和model.cs文件的命名空间 2:csproj 那么它究竟是给谁用的呢?那是给开发工具用的,例如我们在熟悉不过的Visual Studio,以及大家可以没有接触 ...
- WPF Application 执行顺序
public static void Main() { ApplicationClass.App app = new ApplicationClass.App();app.InitializeComp ...
随机推荐
- 【学习笔记】锋利的jQuery(二)DOM操作
一.获取DOM节点 //找祖宗 parent() parents() closest() //找后代 children(); find(); //找兄弟 next()/nextAll() prev() ...
- 不是技术牛人,如何拿到国内IT巨头的Offer【转】
转:http://blog.csdn.net/lsldd/article/details/13506263 不久前,byvoid面阿里星计划的面试结果截图泄漏,引起无数IT屌丝的羡慕敬仰.看看这些牛人 ...
- [转]iOS IPC via NSFileCoordinator and NSFilePresenter
Source:http://mjtsai.com/blog/2014/11/21/ios-ipc-via-nsfilecoordinator-and-nsfilepresenter/ 为什么每次我想到 ...
- [转]Top 10 DTrace scripts for Mac OS X
org link: http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/ Top 10 DTra ...
- Sublime中开发Ruby
Ruby:Sublime中开发Ruby需要注意的Encoding事项 目录 背景Sublime相关默认的文件存储编码:UTF8默认的输出控制台编码:UTF8修改默认的输出控制台编码Ruby相关默认的代 ...
- 伪ajax上传文件
伪ajax上传文件 最近在折腾伪ajax异步上传文件. 网上搜索了一下,发现大部分方法的input file控件都局限于form中,如果是在form外的呢? 必须动态生成一个临时form和临时if ...
- 【c++】指针参数是如何传递内存的
[c++]指针参数是如何传递内存的 如果函数的参数是一个指针,不要指望用该指针去动态申请内存.如下: void GetMemory(char *p, int num) { p = (char *) ...
- Centos 64位 Install certificate on apache 即走https协议
Centos 64位 Install certificate on apache 即走https协议 一: 先要apache 请求ssl证书的csr 一下是步骤: 重要注意事项 An Importan ...
- elasticsearch data importing
ElasticSearch stores each piece of data in a document. That's what I need. Using the bulk API. Trans ...
- Django入门实践(一)
Django入门实践(一) Django编程思路+入门 认识Django有一个多月了,我觉得学习Django应该先理清它的编程思路.它是典型的MVC框架(在Django里也称MTV),我觉得Djang ...