您的位置:首页 > 移动开发

WPF程序设计指南: The Application and the Window

2010-08-17 21:25 495 查看
1. 最简单的WPF程序: A console application project: say hello.

需要引用的DLL: PresentationCore, PresentationFramework, System, WindowBase

继承Application类,以利用其方法

using System;
using System.Windows;
using System.Windows.Input;

namespace Petzold.InheritTheApp
{
class InheritTheApp : Application
{
[STAThread]
public static void Main()
{
InheritTheApp app = new InheritTheApp();
app.Run();
}
protected override void OnStartup(StartupEventArgs args)
{
base.OnStartup(args);

Window win = new Window();
win.Title = "Inherit the App";
win.Show();
}
protected override void OnSessionEnding(SessionEndingCancelEventArgs args)
{
base.OnSessionEnding(args);

MessageBoxResult result =
MessageBox.Show("Do you want to save your data?",
MainWindow.Title, MessageBoxButton.YesNoCancel,
MessageBoxImage.Question, MessageBoxResult.Yes);

args.Cancel = (result == MessageBoxResult.Cancel);
}
}
}


4. Window 和 Application 类的一些properties

Application:

MainWindow: Application的主窗口,默认为第一个被创建的窗口

指定主窗口:MainWindow=win;

ShutdownMode: Application的结束模式。

Windows,Application所包含的所有窗口。

Window:

ShowInTask: Window是否在任务栏中显示。

owner: Window的拥有者(也是Window),“被拥有者”一定出现在“拥有者”前面,“拥有者”关闭或者最小化,“被拥有者”也会关闭或者消失。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐