WPF 笔记1——分析WPF程序文件

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

看B站刘铁猛老师视频学习WPF

1、创建WPF项目

打开VS新建一个WPF项目文件结构如下图

通常 xxx.xaml、 xxx.xaml.cs是一组文件用来定义一个名称是xxx的类。

2、xxx.xaml文件剖析

<Window x:Class="WpfApp1.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:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        
    </Grid>
</Window>

1x:Class="WpfApp1.MainWindow" 表示xmal文件编辑的结果合并到WpfApp1.MainWindow类中

2xxx.xaml.cs文件构造方法中的InitializeComponent()方法就是xxx.xaml编辑生成的

3xmlns表示引用命名空间相等与cs文件里的“using 命名空间”

4xmlns="......"表示这是默认命名空间对应的标签书写时不用写前缀同一个xmal文件中只能有一个默认命名空间

4xmlns:xx 表示应用的命名空间前缀是xx如果要使用这个命名空间的类aaa时需要写成

<xx:aaa></xx:aaa>

5xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 引用的命名空间与控件、布局相关
6xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 引用的命名空间与编译、解析xaml文件相关

如果要引用的命名空间在当前程序集中通常用xmlsn:local

xmlns:local="clr-namespace:WpfApp1"

3、App.xaml文件

App类相当与winform程序中的static class Program类

StartupUri="MainWindow.xaml"相当于winform程序中的Application.Run(new MainView())表示程序运行是首先打开的是哪个窗体界面

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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

“WPF 笔记1——分析WPF程序文件” 的相关文章