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.

最新文章

  1. 油猴 greasemonkey 背景音乐 火狐 chrome 背景音乐
  2. universal image loader自己使用的一些感受
  3. 【转】 MySQL与PostgreSQL:该选择哪个开源数据库?哪一个更好?
  4. [Effective JavaScript 笔记] 第6条:了解分号插入的局限
  5. 内容提供者Content Provider
  6. visual 2008中error PRJ0003 : 生成 cmd.exe 时出错
  7. PDF出力相关资料
  8. C++ —— 时间与日期
  9. poj1410
  10. hdu 3911 Black And White(线段树)
  11. 带你走近AngularJS 之创建自定义指令
  12. RESTful协议
  13. Leetcode:0002(两数之和)
  14. pageObject+selenium
  15. 【JS】中ajax的URL中包含中文,后台接收乱码
  16. POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
  17. shell :将标准输出及标准错误输出写到指定文件
  18. ABP框架系列之二十四:(Email-Sending-EF-电子邮件发送)
  19. A1092. To Buy or Not to Buy
  20. 《DSP using MATLAB》Problem 5.38

热门文章

  1. input框blur事件 ie问题
  2. 3.Struts2-Result
  3. 5.Linux 软件安装管理
  4. fastadmin 金额 字段类型及html验证
  5. 第六章&#183;Logstash深入-收集java日志
  6. Rsync+Sersync实时同步数据目录
  7. luogu4366 [Code+#4]最短路[优化建边最短路]
  8. (web)个人项目(挖宝网)
  9. PHP类知识----静态属性和方法
  10. 将页面内搜索结果高亮显示(使用mark.js),且页面顶部定位到第一个搜索结果