Walkthrough: My first WPF desktop application

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.

原文地址:https://www.cnblogs.com/chucklu/p/11225213.html

时间: 2024-08-29 18:24:26

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

六,WPF的Application类

Application.ShutdownMode属性:通过,只要有一个窗口还没有关闭,Application类就保持应用程序处于有效状态,如果这不是所期望的行为,就可以调整该属性. 应用程序事件 Application提供了为数不多的几个非常有用的事件,如下图所示: 有两种选择用于处理事件:在XAML中使用事件特性的方式关联事件处理程序,或重写相应的受保护方法,当重写应用程序方法时,推荐首先调用基类的实现,通常,基类的实现只是引发相应的应用程序事件. 初始界面(SplashScreen) WPF

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

最近开始写一些WPF的小Sample和文章,但是毕竟WPF应用程式不像Silverlight那么方便的只要装个Plugin就可以透过浏览器来看执行结果,因此把脑筋动到了改用WPF Browser Application上,虽然它是WPF,但是一样可以透过浏览器来执行,这样就可以一边看文章一边看范例. 首先,来看看IE9的设定方式: 在IE9预设的设定下,是没办法正常浏览XBAP的,得要更改一下设定才行,还没更改设定之前看到的画面可能会像下图: 还好要开始这个功能非常的简单,只要点选IE9功能表的

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. Published folder like this: PublishedFolder\MyApp.xbap PublishedFolder\setup.exe PublishedFolder\Application Files\MyApp_0_0_0_1\ MyApp.xbap Published

WPF中Application.Current的使用

原文:WPF中Application.Current的使用 WPF程序对应一个Application对象,当前的Application对象可以通过Application.Current获取,通过获取到的Application对象,我们可以做以下的事情: Application.Current.FindResource("资源名");//获取程序中定义的资源 Application.Current.MainWindow;//获取程序中定义的主窗体 Application.Current.

wpf(Application 如何创建一个事件,及其Application相关的属性)

1.如何关闭wpf程序.应用程序的关闭只有调用其shutdown方法才可以.shutdown有三种属性.OnLastWindowClose,OnMainWindowClose,OnExplicitShutdown 1)通过在App.xaml中直接设置.shutdown="OnExplicitShutdown": 2)第二种方式:删除App.xaml文件,自己创建一个App.cs类,在main方法中: (建立Application对象,建立win窗体对象略) app.shutdown=s

WPF入口Application

1.WPF和 传统的WinForm 类似, WPF 同样需要一个 Application 来统领一些全局的行为和操作,并且每个 Domain (应用程序域)中只能有一个 Application 实例存在.和 WinForm 不同的是 WPF Application 默认由两部分组成 : App.xaml 和 App.xaml.cs,将定义和行为代码相分离.当然,这个和WebForm 也比较类似.XAML 从严格意义上说并不是一个纯粹的 XML 格式文件,它更像是一种 DSL(Domain Spe

Building a desktop application with Electron

非常棒的Electron入门文章: https://medium.com/developers-writing/building-a-desktop-application-with-electron-204203eeb658

20 Interesting WPF Projects on CodePlex

20 Interesting WPF Projects on CodePlex (Some for Silverlight too) Pete Brown - 22 November 2010 In no particular order, here's a selection of interesting and recently maintained WPF projects I've found on CodePlex. This is by no means a complete lis

DotNetCore 3.0 助力 WPF 开发

DotNetCore Is AnyWhere. 前言 Visual Studio 2019 已经正式发布了,DotNetCore 3.0 的正式版也指日可待.在之前的版本中,作为一名基于微软生态的传统 WPF 程序员看着隔壁同学在开发 DotNetCore 网站时用着各种特性好生羡慕,想着巨硬啥时候能让客户端开发者也能尝尝甜头. 那么,现在是时候可以尝试一下了. 需要说明的一点的是,DotNetCore 3.0 虽然跨平台,但是基于此的 WPF 却是针对 Windows 特定平台的实现,并不能跨