WPF 基础介绍

WPF简介

WPF(Windows Presentation Foundation)是微软推出的基于Windows 的用户界面框架,属于.NET Framework 3.0的一部分。它提供了统一的编程模型、语言和框架,真正做到了分离界面设计人员与开发人员的工作;同时它提供了全新的多媒体交互用户图形界面。

控件分类

布局控件 panel

内容控件 ContentControl 只能容纳一个控件或布局控件

带标题的控件 内容控件可以设置标题 Header

条目控件 可以显示一系列数据,数据类型一般相同ItemControl

带标题的条目控件

特殊内容控件 textbox passwordbox textblock textblockImage

XAML

为构建应用程序界面而创建的一种标记语音

定义一个xaml命名空间

xmlns:[前缀名] = “命名空间描述”;

自定义类或程序集映射语法

xmlns:[必选前缀] = "clr-namespace:[命名];assembly = [程序集名称];

WPF应用程序的组成

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bY66FRzw-1650803868184)(C:\Users\Administrator\AppData\Roaming\marktext\images\2022-04-21-16-31-09-image.png)]

App.xaml 设置应用程序起始文件 系统级资源

MainWindow.xaml window界面 WPF应用程序界面与xaml设计文件

AssemblyInfo.cs 反射当前自己程序的字段或者类等

App.xaml

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

    </Application.Resources>
</Application>

StartupUri=“MainWindow.xaml” 指定程序启动加载的窗体

Application.Resources 定义整个WPF应用程序的相关资源

一个xaml文件至少要有两个命名空间 默认命名空间 带x前缀的命名空间

MainWindow.xaml

<Window x:Class="WPF_Controls.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF_Controls"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>

    </Grid>
</Window>

mc:Ignorable=“d” 可以忽略xmlns:d中的一些特性

Title=“MainWindow” Height=“450” Width=“800” 窗体标题名称 窗体高度 窗体宽度

window 继承ContentControl 内容控件 只能包含一个控件或者一个布局控件

Grid 继承panel 继承布局控件 可以包含多个控件

Window 属性:

ShowInTaskbar 窗口是否具有任务栏按钮

WindowStartupLocation 窗口首次显示位置

WindowState 指示窗口是最大化,最小化或正常尺寸显示

Topmost 指示窗体是否置顶

Icon 设置窗体图标

Window事件:

Loaded 当窗体第一次加载时发生

Closing 当窗体关闭时发生

AssemblyInfo.cs

using System.Windows;

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                                     //(used if a resource is not found in the page,
                                     // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
                                              //(used if a resource is not found in the page,
                                              // app, or any theme specific resource dictionaries)
)]

//where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)

//特定于主题的资源字典的位置

//(如果在页面中没有找到资源,则使用

//或应用程序资源字典)

//where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)

//通用资源字典的位置

//(如果在页面中没有找到资源,则使用

//应用程序,或任何主题特定的资源字典)

//设置当前WPF程序使用系统默认主题

[assembly: ThemeInfo("设置主题样式")]

// 程序集标题

[assembly: AssemblyTitle("程序集标题")]

// 程序集描述

[assembly: AssemblyDescription("程序集描述")]

// 产品名称

[assembly: AssemblyProduct("产品名称")]

// 公司

[assembly: AssemblyCompany("公司名称")]

// 合法商标

[assembly: AssemblyTrademark("合法商标")]

// 产品的内部名称

[assembly: AssemblyCulture("产品的内部名称")]

// 版权

[assembly: AssemblyCopyright("Copyright 2014")]

// 程序集的版本信息由下面四个值组成:

//

// 主版本

// 次版本

// 内部版本号

// 修订号

//

// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,

// 方法是按如下所示使用“*”:

[assembly: AssemblyVersion("1.0.0.0")]

// 控制程序集中所有类型对COM的可访问性

[assembly: ComVisible(false)]

// 配置文件,如零售、发布、调试等信息。程序集在运行时不会使用该信息

[assembly: AssemblyConfiguration("")]

如下所示使用“*”:

[assembly: AssemblyVersion(“1.0.0.0”)]

// 控制程序集中所有类型对COM的可访问性

[assembly: ComVisible(false)]

// 配置文件,如零售、发布、调试等信息。程序集在运行时不会使用该信息

[assembly: AssemblyConfiguration(“”)]

  • 25
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值