Walkthrough: My first WPF desktop application

This article shows you how to develop a Windows Presentation Foundation (WPF) desktop application that includes the elements that are common to most WPF applications:

Extensible Application Markup Language (XAML) markup, code-behind, application definitions, controls, layout, data binding, and styles. To develop the application, you'll use Visual Studio.

This walkthrough includes the following steps:

  • Use XAML to design the appearance of the application's user interface (UI).

  • Write code to build the application's behavior.

  • Create an application definition to manage the application.

  • Add controls and create the layout to compose the application UI.

  • Create styles for a consistent appearance throughout the application's UI.

  • Bind the UI to data, both to populate the UI from data and to keep the data and UI synchronized.

By the end of the walkthrough, you'll have built a standalone Windows application that allows users to view expense reports for selected people. The application is composed of several WPF pages that are hosted in a browser-style window.

Tip

The sample code that is used to build this walkthrough is available for both Visual Basic and C# at Walkthrough WPF App Sample Code.

You can toggle the code language of the sample code between C# and Visual Basic by using the </> drop-down on the upper right side of this article.

Create the application project

The first step is to create the application infrastructure, which includes an application definition, two pages, and an image.

  1. Create a new WPF Application project in Visual Basic or Visual C# named ExpenseIt:

    1. Open Visual Studio and select Create a new project under the Get started menu.

      The Create a new project dialog opens.

    2. In the Language dropdown, select either C# or Visual Basic.

    3. Select the WPF App (.NET Framework) template and then select Next.

The Configure your new project dialog opens.

4.Enter the project name ExpenseIt and then select Create.

Visual Studio creates the project and opens the designer for the default application window named MainWindow.xaml.

2.Open Application.xaml (Visual Basic) or App.xaml (C#).

This XAML file defines a WPF application and any application resources.

You also use this file to specify the UI, in this case MainWindow.xaml, that automatically shows when the application starts.

Your XAML should look like the following in Visual Basic:

And like the following in C#:

StartupUri是启动文件

<Application x:Class="CardQuery.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CardQuery"
StartupUri="MainWindow.xaml">
<Application.Resources> </Application.Resources>
</Application>

3.

  • Open MainWindow.xaml.

    This XAML file is the main window of your application and displays content created in pages. The Window class defines the properties of a window, such as its title, size, or icon, and handles events, such as closing or hiding.

Walkthrough: My first WPF desktop application的更多相关文章

  1. WPF的Application类

    本节主要介绍一下Application类的部分功能,我们首先来看一下如何使用Application类来加载一个窗口: 我们首先创建一个控制台程序,并引入相关的dll,然后修改Main()方法. [ST ...

  2. WPF之application对象

    WPF:Application简介 Application是一个地址空间,在WPF中应用程序就是在System.Windows命名空间下的一个Application实例.一个应用程序只能对应一个App ...

  3. How to update WPF browser application manifest and xbap file with ‘mage.exe’

    老外参考文章1 老外参考文章2 I created a WPF browser application MyApp then published it by ClickOnce in VS2008. ...

  4. 使用IE9、FireFox与Chrome浏览WPF Browser Application(.XBAP)的方式

    最近开始写一些WPF的小Sample和文章,但是毕竟WPF应用程式不像Silverlight那么方便的只要装个Plugin就可以透过浏览器来看执行结果,因此把脑筋动到了改用WPF Browser Ap ...

  5. WPF 的 Application.Current.Dispatcher 中,为什么 Current 可能为 null

    原文:WPF 的 Application.Current.Dispatcher 中,为什么 Current 可能为 null 在 WPF 程序中,可能会存在 Application.Current.D ...

  6. WPF 的 Application.Current.Dispatcher 中,Dispatcher 属性一定不会为 null

    原文:WPF 的 Application.Current.Dispatcher 中,Dispatcher 属性一定不会为 null 在 WPF 程序中,可能会存在 Application.Curren ...

  7. WPF基础——Application

    一.Application介绍 WPF中的Application对象用来进行一些全局的行为和操作,并且每个 Domain (应用程序域)中仅且只有一个 Application 实例存在.WPF App ...

  8. WPF入口Application

    1.WPF和 传统的WinForm 类似, WPF 同样需要一个 Application 来统领一些全局的行为和操作,并且每个 Domain (应用程序域)中只能有一个 Application 实例存 ...

  9. 【WPF】Application应用程序启动

    wpf应用程序在启动的时候会自动创建Main函数并调用Application实例的run(),从而启动Application进程.Main函数在一个App.g.cs文件中,App.g.cs文件的位置在 ...

随机推荐

  1. 封装一些简单的 dom 操作

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  2. 把json1赋值给json2,修改json2的属性,json1的属性也一起变化

    let json1 = { a: 1}let json2 = json1json2.a = 5 console.log(json1.a) // 5 console.log(json2.a) // 5 ...

  3. 密码基础知识(2)以RSA为例说明加密、解密、签名、验签

    密码基础知识(1)https://www.cnblogs.com/xdyixia/p/11528572.html 一.RSA加密简介 RSA加密是一种非对称加密.是由一对密钥来进行加解密的过程,分别称 ...

  4. 第五篇python进阶之深浅拷贝

    目录 第五篇python进阶之深浅拷贝 一.引言 1.1可变 和不可变 二.拷贝(只针对可变数据类型) 三.浅拷贝 四.深拷贝 第五篇python进阶之深浅拷贝 一.引言 1.1可变 和不可变 id不 ...

  5. Pysnooper 一款大受欢迎的Debug模块

    Github地址 安装 PIP pip install pysnooper import pysnooper @pysnooper.snoop() def number_to_bits(number) ...

  6. STM32/MINI

  7. @font-face字图标问题

    链接:http://www.exp99.com/htmlcss/htmlcss_229.html

  8. c++分布式服务框架teamtalk

    这是蘑菇街开发的内部通讯软件,记录一下.可以参考学习 https://github.com/meili/TeamTalk

  9. 记一下拷贝windows下文件到linux下的方法

    去官网下载的Putty中包含了如下文件: 其中pscp.exe是一个远程复制文件的工具. 官网:https://www.chiark.greenend.org.uk/~sgtatham/putty/l ...

  10. 2019.9.30 ErrorWidget 的使用

    开发过程中总会碰见页面出现错误的情况,这时候整个页面一片红, 如下 测试阶段出现这样的问题就算了,万一正式环境也出现这个就要不和谐了.所以就有了ErrorWidget.这个是要在最底层设置一下就可以屏 ...