WPF(Windows Presentation Foundation)
是微软推出的基于Windows 的用户界面框架,属于.NET Framework 3.0的一部分。它提供了统一的编程模型、语言和框架,真正做到了分离界面设计人员与开发人员的工作;同时它提供了全新的多媒体交互用户图形界面。
文件
xaml文件:可扩展应用程序标记语言
App.xaml
<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>
App.config-XML文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
MainWindow.xaml文件
共包含两个文件:
MainWindow.xaml文件承担WPF框架中视图界面作用,类似于设计界面,这个设计界面可以使用xaml语言进行开发
MainWindow.xaml.cs文件承担WPF框架中C#语言编程功能,它相对而言比Winform程序的图形界面效果更好
xml文件:可扩展标记语言
html文件:超文本标记语言
CS文件编程
初步布局采取画布布局-类似于winform中使用像素设置
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/>
</Window>
默认提供两个标签:Window标签和Grid标签
Window标签:承担整个窗体结构功能
Grid标签:承担窗体中的一个容器,但是它内部的布局方式是以网格形式布局目前使用Canvas布局
<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="打字游戏" Height="450" Width="800" Loaded="Window_Loaded">
<Canvas x:Name="BG">
</Canvas>
</Window>
回到CS文件中进行编程
当在CS文件中设置this的大小不用考虑Canvas大小,前提是看清楚
在window和Canvas之间的四周边缘有四个锚点,默认处于连接状态,使用鼠标单击之后就会断开,如果那个方向断开,则设置this大小则Canvas不予理会。