C# WPF编程-布局

布局

WPF布局原则

WPF窗口只能包含单个元素。为在WPF窗口中放置多个元素并创建更贴近实用的用户界面,需要在窗口上放置一个容器,然后在这个容器中添加其他元素。
造成这一限制的原因是Window类继承自ContentControl类。

在WPF窗口布局需要遵循以下几条重要原则:

  • 不应显示设定元素的尺寸:元素应当可以改变尺寸以适合他们的内容。可通过设置最大和最小尺寸来限制可以接受的控件尺寸范围。
  • 不应使用屏幕坐标指定元素的位置:元素应当由它们的容器根据它们之间的尺寸、顺序以及其他特定于具体布局容器的信息进行排列。元素之间添加空白空间,可使用Margin属性。
  • 布局容器的子元素“共享”可用的空间:如果空间允许,布局容器会根据每个元素的内容尽可能为元素设置更合理的尺寸。
  • 可嵌套的布局容器:典型的用户界面使用Grid面板作为开始,Grid面板是WPF中功能最强大的容器,Grid面板可包含其他布局容器,包含的这些容器以更小的分组排列元素,如带有标题的文本框、列表框中的项、工具栏上的图标以及一列按钮等。

布局过程

WPF布局包括两个阶段:测量(measure)阶段和排列(arrange)阶段。测量阶段容器遍历所有子元素,并询问子元素它们所期望的尺寸。排列阶段,容器在合适的位置放置子元素。
注意:布局容器不能提供任何滚动支持。滚动是由特定的内容控件-ScrollViewer提供。

布局容器

所有WPF布局容器都是派生自System.Windows.Controls.Panel抽象类的面板。Panel类添加了少量成员,包括三个共有属性。

在这里插入图片描述
Panel类的共有属性:

  • Background:该属性是用于为面板背景着色的画刷。
  • Children:该属性是在面板中存储的条目集合。
  • IsItemsHost:该属性是一个布尔值,如果面板用于显示与ItemsControls控件关联的项,该属性值为true。

核心布局面板:

  • StackPanel:在水平或垂直的堆栈中放置元素。
  • WrapPanel:在一系列可换行的行中放置元素。水平方向,从左到右放置元素。垂直方向,从上到下放置元素。
  • DockPanel:更加容器的整个边界调整元素。
  • Grid:根据不可见的表格在行个列中排列元素,这是最灵活、最常用的容器之一。
  • UniformGrid:在不可见但是强制所有单元格具有相同尺寸的表中放置元素。
  • Canvas:使用固定坐标绝对定位元素。对于尺寸可变的窗口,不适合使用该布局容器。

StackPanel和WrapPanel面板主要用来控制用户界面中一小部分的布局细节,并非用于控制整个窗口布局。

更专业的面板:

  • TabPanel:在TabPanel面板中包含多个选项卡。
  • ToolbarPanel:工具栏中的多个按钮。
  • ToolbarOverflowPanel:Toolbar控件的溢出菜单中的多个命令。
  • VirtualizingStackPanel:数据绑定列表控件使用该面板以大幅降低开销。
  • InkCanvas:该控件和Canvas控件类似,但该控件支持处理平板电脑上的手写笔输入。

布局属性

名称说明
HorizontalAlignment当水平方向上有额外的空间时,该属性决定了子元素在布局中如何定位。可选值:Center、Left、Right或Stretch等属性值
VerticalAlignment当垂直方向上有额外的空间时,该属性决定了子元素在布局中如何定位。可选值:Center、Top、Bottom或Stretch等属性值
Margin该属性用于在元素的周围添加一定的空间。顶部、底部、左边、右边添加空间
MinWidth和MinHeight这两个属性用于设置元素的最小尺寸
MaxWidth和MaxHeight这两个属性用于设置元素的最打尺寸
Width和Height这两个属性用于设置元素的尺寸

Border控件

Border控件不是布局面板,而是非常便于使用的元素,经常与布局面板一起使用。
Border类的属性:

Background使用Brush对象设置边框中所有内容后面的背景。
BorderBrush和BroderThickness使用Brush对象设置位于Border对象边缘的边框的颜色,并设置边框的宽度。为显示边框必须设置这两个属性
CornerRadius该属性设置边框圆角
Padding该属性在边框和内部的内容之间添加空间
<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid Name="grid1">
        <Border Margin="5" Padding="5" Background="LightGreen"
        BorderBrush="SteelBlue" BorderThickness="3,5,3,5"
        CornerRadius="8" VerticalAlignment="Top">
            <StackPanel Orientation="Vertical" Margin="5">
                <Label Margin="3" HorizontalAlignment="Center">按钮 StackPanel布局</Label>
                <Button Margin="3,0,0,0" MaxWidth="200" MinWidth="100">按键1</Button>
                <Button HorizontalAlignment="Right">按键2</Button>
                <Button HorizontalAlignment="Stretch">按键3</Button>
            </StackPanel>
        </Border>
    </Grid>
</Window>

在这里插入图片描述

常用布局

StackPanel布局

<Window x:Class="WpfHelloWorld.Window1"
        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:WpfHelloWorld"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800">
    <StackPanel>
        <Label>按钮 StackPanel布局</Label>
        <Button>按键1</Button>
        <Button>按键2</Button>
        <Button>按键3</Button>
    </StackPanel>
</Window>

在这里插入图片描述
通过设置Orientation属性,改变排列方向
< StackPanel Orientation=“Horizontal”> 水平方向
< StackPanel Orientation=“Vertical”> 垂直方向
在这里插入图片描述

<StackPanel Orientation="Vertical">
    <Label HorizontalAlignment="Center">按钮 StackPanel布局</Label>
    <Button HorizontalAlignment="Left">按键1</Button>
    <Button HorizontalAlignment="Right">按键2</Button>
    <Button HorizontalAlignment="Stretch">按键3</Button>
</StackPanel>

在这里插入图片描述

WrapPanel布局

WrapPanel面板在可能得空间中,以一次一行或一列的方式布局控件。

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid Name="grid1">
        <WrapPanel Margin="10">
            <Button VerticalAlignment="Top">Top Button</Button>
            <Button MinHeight="80" >Tall Button</Button>
            <Button VerticalAlignment="Bottom">Bottom Button</Button>
            <Button>Stretch Button</Button>
            <Button VerticalAlignment="Center">Centered Button</Button>
        </WrapPanel>
    </Grid>
</Window>

在这里插入图片描述

DockPanel布局

DockPanel面板,沿着一条外边缘来拉伸所包含的控件。

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid Name="grid1">
        <DockPanel LastChildFill="True">
            <Button DockPanel.Dock="Top">Top Button</Button>
            <Button DockPanel.Dock="Bottom">Bottom Button</Button>
            <Button DockPanel.Dock="Left">Left Button</Button>
            <Button DockPanel.Dock="Right">Right Button</Button>
            <Button>Remaining Space</Button>
        </DockPanel>
    </Grid>
</Window>

在这里插入图片描述

Grid布局

Grid面板是WPF中功能最强大的布局容器。Grid面板也是将窗口分割成更小区域的理想工具。Grid面板常作为窗口的顶级容器。Grid.ShowGridLines属性设置为true,可以显示面板网格线。
Grid面板通过使用对象填充Grid.ColumnDefinitions和Grid.RowDefinitions集合来创建网格。

Grid布局定义:

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid ShowGridLines="True" Name="grid1">
        <Grid.RowDefinitions>
            <!-- 两行 -->
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <!-- 三列 -->
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
    </Grid>
</Window>

在这里插入图片描述

Grid布局添加元素

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid ShowGridLines="True" Name="grid1">
        <Grid.RowDefinitions>
            <!-- 两行 -->
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <!-- 三列 -->
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <!-- 网格布局添加元素 -->
        <Button Grid.Row="0" Grid.Column="0">Top Left</Button>
        <Button Grid.Row="0" Grid.Column="1">Middle Left</Button>
        <Button Grid.Row="1" Grid.Column="2">Bottom Right</Button>
        <Button Grid.Row="1" Grid.Column="1">Bottom Middle</Button>
    </Grid>
</Window>

在这里插入图片描述

调整行和列
Grid面板支持一次三种设置尺寸的方式:

  • 绝对设置尺寸方式:使用设备无关点位的准确地设置尺寸。难以适应内容大小和容器大小的改变。
  • 自动设置尺寸方式:每行和每列的尺寸刚好满足需要。这是最有用的尺寸设置方式。
  • 按比例设置尺寸方式:按比例将空间分割到一组行和列中。这是对所有行和列的标准设置。
  1. 绝对宽度:
    < ColumnDefinition Width=“100”>< /ColumnDefinition>
  2. 自动尺寸:
    < ColumnDefinition Width=“Auto”>< /ColumnDefinition>
  3. 比例尺寸:
    < ColumnDefinition Width=“*”>< /ColumnDefinition>

如有两行时按比例设置尺寸,第一行的高度是第二行高度的一半:
< RowDefinition Height=“*”>< /RowDefinition>
< RowDefinition Height=“2*”>< /RowDefinition>

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid ShowGridLines="True" Name="grid1">
        <Grid.RowDefinitions>
            <!-- 两行 -->
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="2*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <!-- 三列 -->
            <ColumnDefinition Width="100"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <!-- 网格布局添加元素 -->
        <Button Grid.Row="0" Grid.Column="0">Top Left</Button>
        <Button Grid.Row="0" Grid.Column="1">Middle Left</Button>
        <Button Grid.Row="1" Grid.Column="2">Bottom Right</Button>
        <Button Grid.Row="1" Grid.Column="1">Bottom Middle</Button>
    </Grid>
</Window>

在这里插入图片描述

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid ShowGridLines="True" Name="grid1">
        <Grid.RowDefinitions>
            <!-- 两行 -->
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBox Margin="10" Grid.Row="0">测试文本</TextBox>
        <StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
            <Button Margin="10,20,2,20" Padding="3">确认</Button>
            <Button Margin="2,10,10,10" Padding="5">取消</Button>
        </StackPanel>
    </Grid>
</Window>

在这里插入图片描述

跨越行和列
使元素跨越多个单元格的属性RowSpan和ColumnSpan。

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid ShowGridLines="True" Name="grid1">
        <Grid.RowDefinitions>
            <!-- 两行 -->
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <TextBlock Margin="10" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Background="Green">测试文本</TextBlock>
        <Button Margin="10,10,10,10" Padding="3" Grid.Row="1" Grid.Column="1">OK</Button>
        <Button Margin="2,20,20,20" Padding="5" Grid.Row="1" Grid.Column="2">Cancel</Button>
        
    </Grid>
</Window>

在这里插入图片描述
分割窗口:
在WPF中,分割条由GridSplitter类表示,它是Grid面板的功能之一。

  • GridSplitter对象必须放在Grid单元格中。
  • GridSpliiter对象,总是改变整行或整列的尺寸。
  • 最初,GridSplitter对象很小不易看见。对于垂直分割条需要将VerticalAlignment属性设为Stretch,并将Width设置为固定值。对于水平分割条,需要设置HorizontalAlignment属性来拉伸,并将Height属性设置为固定值。
  • GridSplitter对齐方式还决定了分割条是水平的还垂直的。
<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    
    <Grid ShowGridLines="False" Name="grid1">
        <Grid.RowDefinitions>
            <!-- 两行 -->
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="100"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition MinWidth="50"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Button Grid.Row="0" Grid.Column="0" Margin="3">Left</Button>
        <Button Grid.Row="0" Grid.Column="2" Margin="3">Right</Button>
        <Button Grid.Row="1" Grid.Column="0" Margin="3">Left</Button>
        <Button Grid.Row="1" Grid.Column="2" Margin="3">Left</Button>

        <GridSplitter Background="Green" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2"
                      Width="10" VerticalAlignment="Stretch" HorizontalAlignment="Center"
                      ShowsPreview="False" >
        </GridSplitter>
    </Grid>
</Window>

ShowsPreview=“False”
在这里插入图片描述

ShowsPreview=“True”
在这里插入图片描述
共享尺寸组
还有一种确定一行或一列尺寸的方法–与其他行或列的尺寸相匹配。共享尺寸的目标是保持用户界面独立部分的一致性。

UniformGrid布局

<UniformGrid Rows="2" Columns="2">
    <Button>Top Left</Button>
    <Button>Top Right</Button>
    <Button>Bottom Left</Button>
    <Button>Bottom Right</Button>
</UniformGrid>

在这里插入图片描述

Canvas布局

Canvas面板允许使用精确的坐标放置元素。可以构建如,为图形工具创建绘图表面。为在Canvas面板中定位元素,需要设置Canvas.Left和Canvas.Top附加属性(也可以设置Canvas.Right和 Canvas.Bottom附加属性)。

<Window x:Class="WpfHelloWorld.Window1"
        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:WpfHelloWorld"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800">
    <Canvas>
        <Button Canvas.Left="10" Canvas.Top="10">(10,10)</Button>
        <Button Canvas.Left="120" Canvas.Top="30">(120,30)</Button>
        <Button Canvas.Left="60" Canvas.Top="80" Width="50" Height="50">(60,80)</Button>
        <Button Canvas.Left="70" Canvas.Top="120" Width="100" Height="50">(70,120)</Button>
        <Button Canvas.Right="200" Canvas.Bottom="200" Width="100" Height="100">(R200,B200)</Button>
    </Canvas>
</Window>

在这里插入图片描述
Z顺序:
如果Canvas面板中有多个相互重叠的元素,可通过设置Canvas.ZIndex附加属性来控制它们的层叠方式。添加的元素通常默认具有相同的ZIndex值0。如果元素ZIndex值相同,就按他们在Canvas.Children集合中的顺序进行显示(依赖于元素在XAML标记中的定义顺序)。
代码调用Canvas.SetZIndex(val)方法,亦可设置新的ZIndex值。

<Button Canvas.Left="60" Canvas.Top="80" Canvas.ZIndex="1"  Width="50" Height="50">(60,80)</Button>

在这里插入图片描述

InkCanvas布局

InkCanvas元素的主要目的是用于接收鼠标和手写笔输入。例如包含一幅图片的InkCanvas元素,可以通过鼠标或手写板进行涂鸦。

<Window x:Class="WpfHelloWorld.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:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:WpfHelloWorld"
        mc:Ignorable="d"
        Title="MainWindow" Height="600" Width="800">

    <InkCanvas Name="inkCanvas" Background="LightYellow" EditingMode="Ink">
        <Image Source="images/1.jpg" InkCanvas.Top="10" InkCanvas.Left="10" Width="500" Height="600"></Image>
    </InkCanvas>

</Window>

在这里插入图片描述

InkCanvasEditingMode枚举值

名称说明
InkInkCanvas元素允许用户绘制批注,默认。
GestureOnlyInkCanvas元素不允许用户绘制画笔批注。但支持特定手势如,拖动。能识别的手势由System.Windos.Ink.ApplicationGesture枚举定义。
InkAndGesture允许用户绘制画笔,也可也识别预定手势
EraseByStroke当单击笔画时,InkCanvas元素会擦除画笔。
EraseByPoint当单击笔画时,擦除笔画中被点击的部分(笔画上的一个点)
Select允许用户选择保存在Children集合中的元素。
None忽略鼠标和手写板输入
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
wpf编程宝典c#2010版pdf(全)上传限制分3包,共118M。本人已检查,全三十三章。918页。 作 者:(美)麦克唐纳,王德才 译 出版社: 清华大学出版 英文名:Pro WPF IN C#2010 Windows Pressentation Foundation in .NET4 本书在亚马逊网站上深受读者好评.由微软公司的最有价值专家Matthew MacDonald倾力而作,凝聚了Matthew多年来积累的丰富实践经验,是目前最全面 的一本介绍WPF编程技术的书籍。书中不仅全面介绍了常见的图形界面编程技术,而且对WPF中非常有特色的文档和打印、音频和视频、动画、3D图形开发、多线程和插件等内容也进行了比较深入的介绍。 第1章 WPF概述   1.1 Windows图形演化   1.1.1 DirectX:新的图形引擎   1.1.2 硬件加速与WPF   1.2 WPF:高级API   1.2.1 Windows窗体将继续保留   1.2.2 DirectX也将继续保留   1.2.3 Silverlight   1.3 分辨率无关性   1.3.1 WPF单位   1.3.2 系统DPI   1.3.3 位图和矢量图形   1.4 WPF体系结构   1.5 WPF4   1.5.1 新特性   1.5.2 WPF工具包   1.5.3 VisualStudio2010   1.6 小结   第2章 XAML   2.1 理解XAML   2.1.1 WPF之前的图形用户界面   2.1.2 XAML变体   2.1.3 XAML编译   2.2 XAML基础   2.2.1 XAML名称空间   2.2.2 代码隐藏类   2.3 XAML中的属性和事件   2.3.1 简单属性与类型转换器   2.3.2 复杂属性   2.3.3 标记扩展   2.3.4 附加属性   2.3.5 嵌套元素   2.3.6 特殊字符与空白   2.3.7 事件   2.3.8 完整的EightBall示例   2.4 使用其他名称空间中的类型   2.5 加载和编译XAML   2.5.1 只使用代码   2.5.2 使用代码和未经编译的XAML   2.5.3 使用代码和编译过的XAML   2.5.4 只使用XAML   2.6 XAML2009   2.6.1 自动事件连接   2.6.2 引用   2.6.3 内置类型   2.6.4 高级的对象创建   2.7 小结   第3章 布局   3.1 理解WPF中的布局   3.1.1 WPF布局原则   3.1.2 布局过程   3.1.3 布局容器   3.2 使用StaCkPanel面板进行简单布局   3.2.1 布局属性   3.2.2 对齐方式   3.2.3 边距   3.2.4 最小尺寸、最大尺寸以及显式地设置尺寸   3.2.5 Border控件   3.3 wrapPanel面板和DockPanel面板   3.3.1 wrapPanel面板   3.3.2 DockPanel面板   ……   第4章 依赖项属性   第5章 路由事件   第6章 控件   第7章 application类   第8章 元素绑定   第9章 命令   第10章 资源   第11章 样式和行为   第12章 形状、画刷和变换   第13章 几何图形和图画   第14章 效果和可视比对象   第15章 动画基础   第16章 高级动画   第17章 控件模板   第18章 自定义元素   第19章 数据绑定   第20章 格式化绑定的数据   第21章 数据视图   第22章 列表、网格和树   第23章 窗口   第24章 页面和导航   第25章 菜单、工具栏和功能区   第26章 声音和视频   第27章 3d绘图   第28章 文档   第29章 打印   第30章 与windows窗体的交互   第31章 多线程   第32章 插件模型   第33章 clickonce部署
WPF编程宝典》是一本经典的WPF(Windows Presentation Foundation)编程指南。WPF是一种用于创建窗口应用程序和用户界面的微软技术,它提供了丰富的图形、动画和交互功能,使开发人员能够创建出现代化的应用程序。 这本书按照从基础到高级的顺序,详细介绍了WPF的各个方面。首先,它解释了WPF的基本概念和架构,包括XAML(可扩展应用程序标记语言)和MVVM(模型-视图-视图模型)模式。它还介绍了如何创建和布局控件、处理事件和命令,并利用数据绑定和样式来实现可扩展的用户界面。 此外,书中还深入讨论了WPF的图形和动画特性。读者将学习如何使用绘图对象、渲染效果和3D图形来创建各种视觉效果。它还介绍了如何使用动画和转换来创建流畅的用户界面过渡和交互效果。 《WPF编程宝典》还包含了一些高级的主题,如使用WCF(Windows Communication Foundation)进行数据通信、使用数据库和Web服务,以及集成其他技术和框架,如Entity Framework和Prism。 这本书以清晰的语言、实用的示例和详细的代码解释,帮助读者理解WPF编程的核心概念和技术,从而能够独立地开发高品质的WPF应用程序。 总的来说,《WPF编程宝典》是一本权威且实用的WPF编程指南,对于想要掌握WPF技术的开发人员来说是一本必读的书籍。无论是初学者还是有经验的开发者,都可以从中获得宝贵的知识和技巧,提升自己在WPF编程领域的能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值