教程10:布局和面板教程
布局和面板教程
本教程致力于显示GUI元素如何相对于其容器定位和调整大小。布局是各种设备上应用程序可用性的关键组成部分。我们还将发现NoesisGUI中可用的各种容器。
元素定位
在FrameworkElement的类公开了用于精确定位子元素的几个属性。本主题讨论四个最重要的属性:HorizontalAlignment,Margin,Padding和VerticalAlignment。了解这些属性的影响很重要,因为它们为控制元素在NoesisGUI中的位置提供了基础。
对准
对齐方式确定子元素如何放置在父元素的分配空间内。换句话说,它确定了提供给元素的空间上的位置。有两种类型的对齐方式:HorizontalAlignment和VerticalAlignment。
水平对齐
该的HorizontalAlignment属性声明的水平对齐特征应用到子元素。下表显示了HorizontalAlignment属性的每个可能值。
<colgroup style="box-sizing: inherit;"><col width="13%" style="box-sizing: inherit;"><col width="87%" style="box-sizing: inherit;"></colgroup>
会员 | 描述 |
---|---|
剩下 | 子元素对齐到父元素分配的布局空间的左侧。 |
中央 | 子元素与父元素分配的布局空间的中心对齐。 |
对 | 子元素与父元素分配的布局空间的中心对齐。 |
拉伸(默认) | 子元素被拉伸以填充父元素分配的布局空间。显式的Width和Height值优先。 |
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 100“ Height = ” 100 “ 保证金= ” 5“ BorderBrush = ”黑色“ BorderThickness = ” 1“ >
<按钮 内容= ”左“ HorizontalAlignment = ”左“ VerticalAlignment = ”“居中” />
</ Border>
<边框 宽度= “ 100” 高度= “ 100” 边距= “ 5” BorderBrush = “黑色” BorderThickness = “ 1” >
<按钮 内容= “居中” HorizontalAlignment = “居中” VerticalAlignment = “”居中“ />
</ Border>
<边框 宽度= ” 100“ 高度= ” 100“页 边距= ” 5 “ BorderBrush = ”黑色“ BorderThickness = ” 1“ >
<按钮 内容= ”右“ HorizontalAlignment = ”右“ VerticalAlignment = ”“居中” />
</ Border>
<Border 宽度= “ 100” 高度= “ 100” 保证金= “ 5” BorderBrush = “黑色” BorderThickness = “ 1” >
<Button Content = “ Stretch” HorizontalAlignment = “ Stretch” VerticalAlignment = “” Center“ />
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/34aaec9ebb4afcc2.png)
垂直对齐
该VerticalAlignment属性描述适用于子元素的垂直对齐特征。下表显示了VerticalAlignment属性的每个可能值。
<colgroup style="box-sizing: inherit;"><col width="13%" style="box-sizing: inherit;"><col width="87%" style="box-sizing: inherit;"></colgroup>
会员 | 描述 |
---|---|
最佳 | 子元素与父元素分配的布局空间的顶部对齐。 |
中央 | 子元素与父元素分配的布局空间的中心对齐。 |
底部 | 子元素与父元素分配的布局空间的底部对齐。 |
拉伸(默认) | 子元素被拉伸以填充父元素分配的布局空间。显式的Width和Height值优先。 |
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 100“ Height = ” 100 “ 保证金= ” 5“ BorderBrush = ”黑色“ BorderThickness = ” 1“ >
<按钮 内容= ”顶部“ HorizontalAlignment = ”居中“ VerticalAlignment = ”“顶部” />
</ Border>
<边框 宽度= “ 100” 高度= “ 100” 边距= “ 5” BorderBrush = “黑色” BorderThickness = “ 1” >
<按钮 内容= “居中” HorizontalAlignment = “居中” VerticalAlignment = “”居中“ />
</ Border>
<边框 宽度= ” 100“ 高度= ” 100“页 边距= ” 5 “ BorderBrush = ”黑色“ BorderThickness = ” 1“ >
<按钮 内容= ”底部“ HorizontalAlignment = ”居中“ VerticalAlignment = ”“底部” />
</ Border>
<Border 宽度= “ 100” 高度= “ 100” 保证金= “ 5” BorderBrush = “黑色” BorderThickness = “ 1” >
<按钮 内容= “拉伸” HorizontalAlignment = “中心” VerticalAlignment = “”拉伸“ />
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/6d10314db5783e50.png)
余量
边距确定一个控件到放置该控件的单元格边界之间的距离。它可以是统一的,也可以指定其所有边的值。例如,Margin =“ 20”意味着将属性left,top,right和bottom都设置为20。Margin =“ 20,10,0,10”分配左边界为20,顶部边界为10,a右边距为0,底边为10。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 150“ Height = ” 50 “ Margin = ” 5“ BorderBrush = ” Black“ BorderThickness = ” 1“ >
<Button Content = ” Margin =“ 0,0,0,0&quot;” 保证金= “ 0” />
</ Border>
<边框 宽度= “ 150” BorderThickness = “ 1” >
<Button Content = “ Margin =” 20,5,10,5“ Margin = “ 20,5,10,5” />
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/dc7e060e5e68027b.png)
填充
填充是控件的边框与其内部内容之间的空间。使用此属性,您可以更改任何控件的默认填充。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 150“ Height = ” 50 ““ 保证金= ” 5“ BorderBrush = ”黑色“ BorderThickness = ” 1“ >
<按钮 内容= ”填充=“ 0,0,0,0&”;“ 填充= “ 0” />
</ Border>
<边框 宽度= “ 150” BorderThickness = “ 1” >
<Button Content = “ Padding =” 5,20,5,10“ 填充= “ 5,20,5,10” />
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/c93cb38d1c138271.png)
货柜
在NoesisGUI中,内置了将容器和控件组合在一起的界面,这些控件和控件构成了层次结构的可视树。容器有四种:内容容器,项目容器,装饰器和面板。
内容容器
内容控件
保留单个子Content的控件。内容可以是字符串,对象甚至其他UIElement。示例:Button,Label和ToolTip。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 150“ Height = ” 50 “ 保证金= ” 5“ >
<按钮 内容= ”按我“ />
</ Border>
<边界 宽度= ” 150“ 高度= ” 50“ 保证金= ” 5“ >
<按钮 HorizontalContentAlignment = ”拉伸“ VerticalContentAlignment = ”拉伸“ 填充= ” 15“>
<矩形 填充= “红色” />
</按钮>
</ Border>
<边框 宽度= “ 150” 高度= “ 50”页 边距= “ 5” >
<标签 内容= “ A标签控件” HorizontalAlignment = “”居中“ VerticalAlignment = “ Center” />
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/c63755cb770cfba7.png)
HeaderedContentControl
甲HeaderedContentControl基本相同的ContentControl中但具有报头,其用于呈现所述内容的报头部分。示例:GroupBox,Expander和TabItem。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 150“ Height = ” 90 “ 保证金= ” 5“ >
<GroupBox Header = ” Group“ HorizontalContentAlignment = ” Stretch“ VerticalContentAlignment = ” Stretch“ >
<矩形 填充= ”红色“ 保证金= ” 10“ />
</ GroupBox>
</ Border>
<Border Width = “ 150” 高度= “ 90” 保证金= “ 5” >
<Expander 标头= “ Expander” padding = “ 16” >
<矩形 填充= “红色” Width = “ 100” 高度= “ 35” />
</ Expander>
</ Border >
<边框 宽度= “ 150” 高度= “ 90” 边距= “ 5” >
<TabControl HorizontalContentAlignment = “拉伸” VerticalContentAlignment = “”拉伸“ >
<TabItem 标头= “制表符” >
<矩形 填充= “红色” 边距=“ 10” />
</ TabItem>
</ TabControl>
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/4c6cbe2620918588.png)
物品容器
ItemsControl
包含多个Item的控件。示例:ListBox,ListView和TreeView。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel
xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x = “ http://schemas.microsoft.com/winfx/2006/xaml”
Orientation = “水平” HorizontalAlignment = “居中” VerticalAlignment = “居中” >
<StackPanel.Resources>
<Style x:Key = “ CyanHeader” TargetType = “ GridViewColumnHeader” >
<Setter 属性= “背景” 值= “ Cyan” />
<Setter 属性= “前景“ 值= ”海军“/>
</ Style>
<DataTemplate x:Key =“ CheckHeader” DataType = “ GridViewColumnHeader” >
<StackPanel Orientation = “ Horizontal” >
<CheckBox />
<TextBlock Text = “ {Binding Header}” />
</ StackPanel>
</ DataTemplate>
<DataTemplate x:Key = “ RefText” >
<边框 背景= “#8080FFFF” BorderBrush = “海军” BorderThickness = “ 1” 填充= “ 6,2” CornerRadius = “ 2” >
<TextBlock Text = “{Binding Name}“ 前景= ”海军“ FontWeight = ”“粗体” />
</ Border>
</ DataTemplate>
<DataTemplate x:Key = “ StockText” >
<Border x:Name = “ Bd” Background = “ LightBlue” 填充= “ 6,2” CornerRadius = “ 2” >
<TextBlock x:Name = “ Txt” 文本= “ {Binding IsEnabled}” 前景= “ SlateGray” />
</ Border>
<DataTemplate.Triggers>
<Trigger SourceName = “ Txt” 属性= “ Text” 值= “ False” >
<设置器 TargetName = “ Bd” 属性= “背景” Value =“ Pink” />
<Setter TargetName = “ Txt” 属性= “ Foreground” Value = “红色” />
</ Trigger>
</DataTemplate.Triggers>
</ DataTemplate>
</StackPanel.Resources>
<Border 宽度= “ 150” 高度= “ 200” 边距= “ 5” >
<StackPanel>
<TextBlock 文本= “季节:” />
<ListBox>
<TextBlock 文本= “ Spring” />
<TextBlock 文本= “ Summer” />
<TextBlock Text = “秋天” />
<TextBlock Text = “冬天” />
</ ListBox>
</ StackPanel>
</ Border>
<边框 宽度= “ 400” 高度= “200“ 保证金= ” 5“ >
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header = “ #Ref”
CellTemplate = “ {StaticResource RefText}”
HeaderContainerStyle = “” {StaticResource CyanHeader}“ />
<GridViewColumn Header = ”产品“ Width = ” 140“ />
<GridViewColumn Header = ”价格€ “ Width = ” 60“
DisplayMemberBinding = ”“ {Binding ActualWidth,StringFormat = F2}” />
<GridViewColumn Header = “ Available”
HeaderTemplate = “” StaticResource CheckHeader}“
CellTemplate = ”{StaticResource StockText}“ />
</ GridView>
</ListView.View>
<TextBlock x:Name = “ ID20041” Text = “紫花苜蓿粉” Margin = “ 5,0” />
<TextBlock x:Name = “ ID13494” Text = “鲜血” Margin = “ 5,0” />
<TextBlock x:Name = “ ID83471” 文字= “ Greensand mix” 边距= “ 5,0” IsEnabled = “ False” />
<TextBlock x:Name = “ ID27856” 文字= “钙石灰” Margin = “ 5,0” / >
<TextBlock x:名称= “ ID74865” 文字= “硝酸智利” 保证金= “ 5,0” />
<TextBlock x:Name = “ ID47286” Text = “棉籽” Margin = “ 5,0” />
<TextBlock x:Name = “ ID27456” Text = “泻盐” Margin = “ 5,0” IsEnabled = “ False “ />
<TextBlock x:Name = ” ID24583“ Text = ”羽毛粉“ Margin = ” 5,0“ />
<TextBlock x:Name = ” ID24659“ Text = ” Humates“ Margin = ” 5,0“ />
</ ListView>
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/a0c28a4b8bf47ec2.png)
HeaderedItemsControl
可以容纳许多任意元素作为特定Header内容的容器。示例:MenuItem,ToolBar和TreeViewItem。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 150“ Height = ” 200 “ 保证金= ” 5“ >
<DockPanel 背景= ”灰色“ LastChildFill = ” False“ >
<Menu DockPanel.Dock = ”顶部“ >
<MenuItem Header = ”文件“ >
<MenuItem Header = “打开” />
<MenuItem Header = “保存”/>
<Separator />
<MenuItem Header = “ Exit” />
</ MenuItem>
</ Menu>
</ DockPanel>
</ Border>
<Border Width = “ 200” Height = “ 200” Margin = “ 5” >
< TreeView 宽度= “ 500” 高度= “ 400” >
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<Image Source = “ Images / monitor.png” Width = “ 24” 高度= “ 24” />
<TextBlock 文本= “计算机” VerticalAlignment = “居中”页 边距= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<Image Source = “ Images /game_pad.png“ 宽度= ” 24“ 高度= ” 24“ />
<TextBlock 文本= ”游戏“ VerticalAlignment = ”中心“ 保证金= ” 4,0,0,0“ />
</ StackPanel>
</ TreeViewItem。标头>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “水平” >
<Image Source = “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “ Duck Hunt” VerticalAlignment = “ Center” 边距= “ 4,0,0,0” />
< / StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<Image Source = “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock Text = “弹跳球” VerticalAlignment = “居中” Margin = “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “程序文件” VerticalAlignment = “”居中“ 保证金= ” 4,0,0,0“ />
</ StackPanel>
</TreeViewItem.Header>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “水平”>
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “认知” VerticalAlignment = “居中”页 边距= “ 4,0,0,0” />
< / StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<Image Source = “ Images / recycle_bin.png” Width = “ 24” 高度= “ 24” />
<TextBlock 文本= “回收站” VerticalAlignment = “居中” 保证金= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “用户” VerticalAlignment = “”居中“ 保证金= ” 4,0,0,0“ />
</ StackPanel>
</TreeViewItem.Header>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel 方向=“水平” >
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “管理员” VerticalAlignment = “中心”页 边距= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<Image Source = “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “ John Doe” VerticalAlignment = “居中” 保证金= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal “ >
<图像 源= ” Images / folder.png“ 宽度= ” 24“ 高度= ” 24“ />
<TextBlock 文本= ” Windows“ VerticalAlignment = ”“居中”页 边距= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel 方向= “水平” >
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “字体” VerticalAlignment = “”中心“页 边距= ” 4,0,0, 0“ />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = ” Horizontal“ >
<Image Source = ” Images / folder.png“ Width = ” 24“ 高度= “ 24” />
<TextBlock 文本= “媒体” VerticalAlignment = “居中” 保证金= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “资源” VerticalAlignment = “”居中“ 保证金= ” 4,0,0,0“ />
</ StackPanel>
</TreeViewItem.Header>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel 方向=“水平” >
<图像 源= “ Images / folder.png” 宽度= “ 24” 高度= “ 24” />
<TextBlock 文本= “主题” VerticalAlignment = “中心” 边距= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
</ TreeViewItem>
<TreeViewItem>
<TreeViewItem.Header>
<StackPanel Orientation = “ Horizontal” >
<Image Source = “ Images / folder.png” Width = “ 24“ 高度= “ 24” />
<TextBlock 文本= “ System32” VerticalAlignment = “ Center” 边距= “ 4,0,0,0” />
</ StackPanel>
</TreeViewItem.Header>
</ TreeViewItem>
</ TreeViewItem>
</ TreeViewItem>
</ TreeView>
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/5c120b399383ee3c.png)
装饰工
装饰器将效果应用于单个Child元素上或周围。示例:Border,BulletDecorator和Viewbox。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><StackPanel xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
方向= “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ >
<Border Width = ” 150“ Height = ” 100 “ 保证金= ” 5“ >
<边框 背景= ”银色“ BorderBrush = ”黑色“ BorderThickness = ” 2“ CornerRadius = ” 5“ 填充= ” 10“ 保证金= ” 10“ >
<矩形 填充= “红色” 宽度= “ 60” 高度= “ 25”/>
</ Border>
</ Border>
<Border Width = “ 150” Height = “ 100” Margin = “ 5” >
<BulletDecorator Margin = “ 10” VerticalAlignment = “ Center” >
<BulletDecorator.Bullet>
<椭圆 宽度= “ 14” 高度= “ 14” 填充= “银色” 描边= “黑色” StrokeThickness = “ 3” />
</BulletDecorator.Bullet>
<TextBlock Text = “子弹装饰器” Margin = “ 5,0,0,0” />
</ BulletDecorator>
</ Border>
<Border 宽度= “ 225” 高度= “ 100”页 边距= “ 5” >
<Viewbox 宽度= “ 200”页 边距= “ 10” >
<TextBlock 文本= “在视图框内” FontSize = “ 8” 背景= “ Pink” 填充= “ 5,2” />
</ Viewbox>
</ Border>
</ StackPanel>
</pre>
![](https://img.haomeiwen.com/i20475064/6fe2b92c05271b52.png)
视图框
Viewbox提供了一种简单的机制来缩放给定空间内的任意内容。默认情况下,Viewbox会在两个维度上拉伸以填充为其赋予的形状(就像大多数控件一样)。但它也具有Stretch属性,可以控制其单个子对象如何在其范围内缩放。的第二个特性Viewbox控件,StretchDirection,控制您是否只是想用它来缩小内容或扩大的内容(而不是做要么)。
注意
Viewbox是使应用程序独立于分辨率的理想容器
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><页面 xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation” >
<网格 背景= “灰色” ShowGridLines = “真实” >
<Grid.RowDefinitions>
<RowDefinition Height = “ *” / >
<RowDefinition Height = “ 3 *” />
<RowDefinition Height = “ *” />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = “ *” />
<ColumnDefinition Width = “ 3 *” />
<ColumnDefinition Width = “ *” />
</Grid.ColumnDefinitions>
<Viewbox Grid.Column = “ 0” Grid.Row = “ 0” Stretch = “统一” >
<Grid>
<矩形 填充= “绿色” />
<Label Content = “左上” />
</ Grid>
</ Viewbox>
<Viewbox Grid.Column = “ 0” Grid.Row = “ 2” Stretch = “ Uniform” >
<网格 背景= “黄色” >
<标签 内容= “左下” />
</ Grid>
</ Viewbox>
<Viewbox Grid.Column = “ 2” Grid.Row = “ 0” Stretch =“统一” >
<网格 背景= “红色” >
<标签 内容= “右上” />
</ Grid>
</ Viewbox>
<Viewbox Grid.Column = “ 2” Grid.Row = “ 2” Stretch = “统一“ >
<网格 背景= ”蓝色“ >
<标签 内容= ”右下“ />
</ Grid>
</ Viewbox>
<Viewbox Grid.Column = ” 1“ Grid.Row = ” 1“ Stretch = ” Uniform“>
<网格 背景= “白色” >
<标签 Content = “ Center” />
</ Grid>
</ Viewbox>
</ Grid>
</ Page>
</pre>
![](https://img.haomeiwen.com/i20475064/2b8bd02c62d87554.png)
面板
NoesisGUI包含六个主要的内置面板,按复杂性和实用性的升序排列:Canvas,StackPanel,UniformGrid,WrapPanel,DockPanel和Grid。
帆布
画布是一种特殊的布局面板,它使用绝对坐标(即使用x和y坐标)分布元素。在画布中使用时,元素不限于任何元素,它可以与其他控件重叠。呈现顺序取决于XAML中元素的声明方式。可以使用Panel.ZIndex属性更改此序列。
画布不对其元素施加任何限制。因此,必须指定单个元素的宽度和高度。您可以使用附加的属性Canvas.Left或Canvas.Right和Canvas.Top或Canvas.Bottom来指定到父级所选边的距离。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><Grid
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“
mc:Ignorable = ” d“
Background = ” LightGray“
TextElement。前景= “黑色”
边距= “ 10” HorizontalAlignment = “中心” VerticalAlignment = “中心” >
<Grid.Resources>
<LinearGradientBrush x:Key = “ BgBrush” StartPoint = “ 0,0” EndPoint = “ 1,1” >
<GradientStop Offset = “ 0” Color = “#FF9BDEFF” />
<GradientStop Offset = “ 1 “ Color = ”#FF69B5FF“ />
</ LinearGradientBrush>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height = “ Auto” />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation = “ Horizontal” HorizontalAlignment = “ Center” Margin = “ 0,8,0,0” >
<TextBlock Text = “画布大小:” />
<TextBlock Text = “ {Binding ActualWidth,ElementName = Canvas}” / >
<TextBlock Text = “ x” />
<TextBlock Text = “ {Binding ActualHeight,ElementName = Canvas}” />
</ StackPanel>
<Canvas x:Name = “ Canvas” Width = “ 380” Height = “ 240” 网格.Row = “1“ 背景= ”白色“ 边距= ” 8“ >
<Border BorderBrush = “黑色” BorderThickness = “ 1” 高度= “ 50” CornerRadius = “ 0,4,4,4” 背景= “ {DynamicResource BgBrush}” Canvas.Left = “ 20” Canvas.Top = “ 15” >
<Grid>
<StackPanel Orientation = “ Horizontal” Margin = “ 2,0,10,0” HorizontalAlignment = “ Left” VerticalAlignment = “” Top“ >
<TextBlock Text = ”“(left =” />
<TextBlock Text = “” {绑定(画布。左),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
<TextBlock Text = “,top =” />
<TextBlock Text = “” {Binding(Canvas.Top),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“” />
<TextBlock Text = “”)/>
</ StackPanel>
<Ellipse Fill = “ Black” Stroke = “#00000000” Width = “ 4” Height = “ 4” HorizontalAlignment = “ Left” VerticalAlignment = “ Top” StrokeThickness = “ 0” Margin = “ -2,-2 ,0,0“ />
</ Grid>
</ Border>
<Border BorderBrush = “黑色” BorderThickness =“ 1” 高度= “ 50” CornerRadius = “ 4,0,4,4” 背景= “ {DynamicResource BgBrush}” Canvas.Right = “ 15” Canvas.Top = “ 35” >
<Grid>
<StackPanel Orientation = “ Horizontal“ Margin = ” 10,0,2,0“ HorizontalAlignment = ” Right“ VerticalAlignment = ”“顶部” >
<TextBlock Text = “”(right =“ />
<TextBlock Text = ”“ {Binding(Canvas.Right),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
<TextBlock Text = “,top =” />
<TextBlock Text = “ {Binding(Canvas.Top),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
<TextBlock Text = ”“)/>
</ StackPanel>
<椭圆 填充= ”黑色“ 笔触= “#00000000” 宽度= “ 4” 高度= “ 4” HorizontalAlignment = “右” VerticalAlignment = “顶部” StrokeThickness = “ 0” 保证金= “ 0,-2,-2,0” />
</ Grid>
</
Grid> </ Grid> </ Grid> 边框> <Border BorderBrush = “黑色” BorderThickness = “ 1” 高度= “ 50” CornerRadius = “ 4,4,4,0” 背景= “ {DynamicResource BgBrush}” Canvas.Left = “ 10” Canvas.Bottom = “ 35” >
<Grid>
<StackPanel Orientation = “ Horizontal” 边距= “ 2,0,10,0” HorizontalAlignment = “ Left” VerticalAlignment = “底部” >
<TextBlock Text = “(left =” />
<TextBlock Text = “” {Binding(Canvas.Left),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“” />
<TextBlock Text = “,bottom =” />
<TextBlock Text =“ {Binding(Canvas.Bottom),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}” />
<TextBlock Text = “)” />
</ StackPanel>
<椭圆 填充= “黑色” 描边= “# 00000000“ 宽度= ” 4“ 高度= ” 4“ HorizontalAlignment = ”左“ VerticalAlignment = ”底部“ StrokeThickness = ” 0“页 边距= ” -2,0,0,-2“ />
</ Grid>
</ Border>
<Border BorderBrush = “黑色” BorderThickness = “ 1” 高度= “ 50” CornerRadius = “ 4,4,0,4” 背景=“ {DynamicResource LightBlueBackground }” Canvas.Right = “ 10” Canvas.Bottom = “ 5” >
<网格 背景= “ {DynamicResource BgBrush}” >
<StackPanel Orientation = “水平” Margin = “ 10,0,2,0” HorizontalAlignment = “右侧” VerticalAlignment = “底部” >
<TextBlock 文本= “(right =” />
<TextBlock 文本= “ {绑定(Canvas.Right),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}}” />
<TextBlock Text = “,bottom =” />
<TextBlock Text =“ {Binding(Canvas.Bottom),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}” />
<TextBlock Text = “)” />
</ StackPanel>
<椭圆 填充= “黑色” 描边= “# 00000000“ 宽度= ” 4“ 高度= ” 4“ HorizontalAlignment = ”右“ VerticalAlignment = ”底部“ StrokeThickness = ” 0“页 边距= ” 0,0,-2,-2“ />
</ Grid>
</ Border>
<Border BorderBrush = “黑色” BorderThickness = “ 1” 高度= “ 30” CornerRadius = “ 0,4,4,4” 背景=“ {DynamicResource BgBrush}” Canvas.Left = “ 160” Canvas.Top = “ 115” >
<Grid>
<StackPanel Orientation = “ Horizontal” 保证金= “ 2,0,10,0” HorizontalAlignment = “ Left” VerticalAlignment = “”顶部” >
<TextBlock Text = “(left =” />
<TextBlock Text = “” {Binding(Canvas.Left),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}“ />
<TextBlock Text = ”, top =“ />
<TextBlock Text = ”{Binding(Canvas.Top),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“” />
<TextBlock Text = “)” />
</ StackPanel>
<Ellipse Fill = “ Black” Stroke = “#00000000” Width = “ 4” Height = “ 4” HorizontalAlignment = “ Left” VerticalAlignment = “” Top“ StrokeThickness = ” 0 “ Margin = ” -2,-2,0,0“ />
</ Grid>
</ Border>
</ Canvas>
</ Grid>
</pre>
![](https://img.haomeiwen.com/i20475064/6f23ec1a94c09763.png)
StackPanel
StackPanel是一个容器,其中子元素排列在水平或垂直方向上的一行中。方向由属性Orientation定义,该属性可以采用两个有效值:
- 垂直:这是默认方向。子项从上到下垂直垂直放置。
- 水平:在这里,项目从左到右一个接一个地放置。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><Grid
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“
mc:Ignorable = ” d“
Background = ” LightGray“
TextElement。前景= “黑色”
边距= “ 10” HorizontalAlignment = “中心” VerticalAlignment = “中心” >
<Grid.Resources>
<LinearGradientBrush x:Key = “ HorBrush” StartPoint = “ 0,0” EndPoint = “ 1,0” >
<GradientStop Offset = “ 0” Color = “#FF9BDEFF” />
<GradientStop Offset = “ 1 “ Color = ”#FF69B5FF“ />
</ LinearGradientBrush>
<LinearGradientBrush x:Key = ” VerBrush“ StartPoint = ” 0,0“ EndPoint = ” 0,1“ >
<GradientStop Offset = ” 0“ Color = ”#FF9BDEFF“ />
<GradientStop Offset = ” 1“ 颜色=“#FF69B5FF” />
</ LinearGradientBrush>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = “ *” />
<ColumnDefinition Width = “ 4” />
<ColumnDefinition Width = “ Auto” />
<ColumnDefinition Width = “ 200” />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition 高度= “自动” />
<RowDefinition 高度= “自动” />
<RowDefinition 高度= “*” />
</Grid.RowDefinitions>
<TextBlock的 文本= “水平StackPanels” 的HorizontalAlignment = “中心“ Grid.ColumnSpan = ” 2“ 保证金= ” 0,8,0,0“ />
<StackPanel x:Name = ”“ StackPanel1” Background = “”白色“ 保证金= ” 8,8,8,0“ Grid.Row = “ 1” 方向= “水平” 水平对齐= “中心” d:LayoutOverrides = “ Height” >
<Border BorderBrush = “ Black” BorderThickness = “ 1” CornerRadius = “ 8” Background = “” {DynamicResource HorBrush}“ Margin = ” 4“ Padding = ” 0“ Width = ” 40“ Height = “ 80” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 利润= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” VerticalAlignment = “顶部”/>
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 裕度= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” />
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 边距= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” 垂直对齐= “底部” />
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 利润= “ 4” 填充= “ 0” 宽度= “ 80” />
</ StackPanel>
<StackPanel x:Name = “ StackPanel2” 背景= “白色” 边距= “ 8” Grid.Row = “ 2” 方向= “ Horizontal” HorizontalAlignment = “ Center” >
<Border BorderBrush = “黑色 BorderThickness = “ 1” CornerRadius = “ 8” Background =“ {DynamicResource HorBrush}” 保证金= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 80” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}“ 边距= ” 4“ 填充= ” 0“ 宽度= ” 40“ 高度= ” 25“ VerticalAlignment = ”顶部“ />
<Border BorderBrush = ”黑色“ BorderThickness = ”1“ CornerRadius = ” 8“ 背景= ” {DynamicResource HorBrush}“ 保证金= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” Margin = “ 4“ 填充= ” 0“ 宽度= ” 40“ 高度= ” 25“ VerticalAlignment = ”底部“ />
<Border BorderBrush = ”黑色“ BorderThickness = ” 1“ CornerRadius = ”8“ 背景= ” {DynamicResource HorBrush}“ 利润= ” 4“ 填充= “ 0” 宽度= “ 80” />
</ StackPanel>
<矩形 填充= “#80808080” Grid.RowSpan = “ 3” StrokeThickness = “ 0” Grid.Column = “ 1” />
<TextBlock Text = “垂直StackPanels“ HorizontalAlignment = ” Center“ Grid.ColumnSpan = ” 2“ d:LayoutOverrides = ” GridBox“ Grid.Column = ” 2“页 边距= ” 0,8,0,0“ />
<StackPanel x:Name = ”“ StackPanel3 ” 背景= “白色” 边距= “ 8” Grid.Row = “ 1” HorizontalAlignment = “居中” VerticalAlignment = “居中” Grid.Column = “ 2” Grid.RowSpan = “ 2” >
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” 填充= “ 0” 宽度= “ 80” 高度= “ 40” />
<Border BorderBrush = “ Black” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 保证金= “ 4” 填充=“ 0” HorizontalAlignment = “左” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 利润= “ 4” 填充= “ 0” HorizontalAlignment = “ Center” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “8“ 背景= ” {DynamicResource VerBrush}“ 保证金= ” 4“ 填充= “ 0” HorizontalAlignment = “右” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” Margin = “ 4“ 填充= ” 0“ 高度= ” 80“ />
</ StackPanel>
<StackPanel x:Name = ” StackPanel4“ 背景= ”白色“ 边距= ” 0,8,8,8“ Grid.Row = ” 1 VerticalAlignment = “居中” Grid.Column = “ 3” d:LayoutOverrides = “ GridBox” Grid.RowSpan = “ 2” >
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 利润= “ 4” 宽度= “ 80” 高度= “ 40” />
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” HorizontalAlignment = “左“ 宽度= ” 25“ 高度= ” 40“ />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” HorizontalAlignment = “ Center” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” HorizontalAlignment = “右” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” 高度= “ 80” />
</ StackPanel>
</ Grid>
</pre>
![](https://img.haomeiwen.com/i20475064/ecbd1ab0a0f65f4c.png)
统一网格
UniformGrid控件提供的布局与Grid布局控件提供的布局相似。它的子控件组织成行和列的表格结构。与Grid控件不同,您没有对布局的细粒度控制。列宽和行高不能修改。这些大小会自动设置,以确保所有列具有相同的宽度,所有行具有相同的高度。此外,在Grid控件允许您为每个子项指定单元格位置的情况下,UniformGrid则不允许。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><Grid xmlns = “ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x = “ http://schemas.microsoft.com/winfx/2006/xaml”
高度= “ 200” 宽度= “ 250” >
<UniformGrid>
<按钮 内容= “按钮1” />
<按钮 内容= “按钮2” />
<按钮 内容= “按钮3” />
<按钮 内容= “按钮4” />
</ UniformGrid>
</ Grid>
</pre>
![](https://img.haomeiwen.com/i20475064/0b64706dbc458a7d.png)
包装面板
WrapPanel几乎类似于StackPanel,但是当它到达面板的边缘时会产生新的一行。因此,如果您调整WrapPanel的大小,内容将自动换行到新行。因此,WrapPanel具有额外的灵活性,可以在空间很重要时包装元素。
另一个区别是WrapPanel根据内容的大小确定大小,而不是像StackPanel那样将其视为无穷大。您还可以使用属性ItemWidth和ItemHeight指定WrapPanel为每个子元素保留的布局分区的大小。这些属性优先于元素自身的宽度和高度。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><Grid
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“
mc:Ignorable = ” d“
Background = ” LightGray“
TextElement。前景= “黑色”
边距= “ 10” HorizontalAlignment = “中心” VerticalAlignment = “中心” >
<Grid.Resources>
<LinearGradientBrush x:Key = “ HorBrush” StartPoint = “ 0,0” EndPoint = “ 1,0” >
<GradientStop Offset = “ 0” Color = “#FF9BDEFF” />
<GradientStop Offset = “ 1 “ Color = ”#FF69B5FF“ />
</ LinearGradientBrush>
<LinearGradientBrush x:Key = ” VerBrush“ StartPoint = ” 0,0“ EndPoint = ” 0,1“ >
<GradientStop Offset = ” 0“ Color = ”#FF9BDEFF“ />
<GradientStop Offset = ” 1“ 颜色=“#FF69B5FF” />
</ LinearGradientBrush>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = “ 250” />
<ColumnDefinition Width = “ 4” />
<ColumnDefinition Width = “ Auto” />
<ColumnDefinition Width = “ 170” />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height = “ Auto” />
<RowDefinition Height = “ 75” />
<RowDefinition Height = “ 170” />
<RowDefinition Height = “ Auto” />
</Grid.RowDefinitions>
<TextBlock Text = “ Horizontal WrapPanels” HorizontalAlignment = “ Center” Grid.ColumnSpan = “ 2” Margin = “ 0,8,0,0” d:LayoutOverrides = “ GridBox” />
<WrapPanel x:Name = “ WrapPanel1” 背景= “”白色“ HorizontalAlignment = ”居中“页 边距= ” 8,8,8,0“ 方向= ”水平“ Grid.Row = ” 1“ VerticalAlignment = ”顶部“ ItemWidth = ”“ {Binding SelectedItem.Content,ElementName = HorItemsWidth} ” ItemHeight = “ {Binding SelectedItem.Content,ElementName = HorItemsHeight}” >
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 边距= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}”页 边距= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” VerticalAlignment = “顶部” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 裕度= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1“ CornerRadius = ” 8“ 背景= ” {DynamicResource HorBrush}“ 边距= ” 4“ 填充= ” 0“ 宽度= ” 40“ 高度= ” 25“ VerticalAlignment = ”底部“/>
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 利润= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8“ 背景= ” {DynamicResource HorBrush}“ 保证金= ” 4“ 填充= ” 0“ 宽度= ” 40“ 高度= ” 25“ />
</ WrapPanel>
<WrapPanel x:Name = ” WrapPanel2“ 背景= “白色” 边距= “ 8” 方向=“水平” Grid.Row = “ 2” ItemWidth = “” {Binding SelectedItem.Content,ElementName = HorItemsWidth}“ ItemHeight = ”“ {Binding SelectedItem.Content,ElementName = HorItemsHeight}” >
<Border BorderBrush = “黑色” BorderThickness = “ 1 “” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 保证金= “ 4” 填充= “ 0” 宽度= “ 40” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “1“ CornerRadius = ” 8“ 背景=“ {DynamicResource HorBrush}” 保证金= “ 4” 填充= “ 0” 宽度= “ 50” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}“ 保证金= ” 4“ 填充= ” 0“ 宽度= ” 60“ 高度= ” 25“ />
<Border BorderBrush = ” Black“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= “ {DynamicResource HorBrush}” 利润= “ 4” 填充=“ 0” 宽度= “ 70” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 保证金= “ 4” 填充= “ 0” 宽度= “ 80” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 保证金= “ 4” 填充= “ 0” 宽度= “ 90” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 边距= “ 4” 填充= “ 0” 宽度= “ 100” 高度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource HorBrush}” 边距= “ 4” 填充= “ 0” 宽度= “ 140” 高度= “25“ />
</ WrapPanel>
<矩形 填充= ”#80808080“ Grid.RowSpan = “ 4” StrokeThickness = “ 0” Grid.Column = “ 1” />
<TextBlock Text = “ Vertical WrapPanels” HorizontalAlignment = “ Center” Grid.ColumnSpan = “ 2” Grid.Column = “ 2” Margin = “ 0,8,0,0” d:LayoutOverrides = “ GridBox” />
<WrapPanel x:Name = “ WrapPanel3” Background = “ White”页 边距= “ 8” Grid.Row = “ 1” Grid.Column = “ 2 “ Grid.RowSpan = ” 2“ 方向= “垂直” VerticalAlignment = “中心” HorizontalAlignment = “ Center” ItemWidth = “” {Binding SelectedItem.Content,ElementName = VerItemsWidth}“ ItemHeight = ”“ {Binding SelectedItem.Content,ElementName = VerItemsHeight}” >
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8 “ 背景= ” {DynamicResource VerBrush}“ 边距= ” 4“ 填充= ” 0“ 宽度= ” 25“ 高度= ” 40“ />
<Border BorderBrush = ”黑色“ BorderThickness = ” 1“ CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 保证金= “ 4” 填充= “ 0” HorizontalAlignment = “左” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush }“ 保证金= ” 4“ 填充= ” 0“ HorizontalAlignment = ”中心“ 宽度= ” 25“ 高度= ” 40“ />
<Border BorderBrush = ”黑色“ BorderThickness = “ 1” CornerRadius = “ 8” Background =“ {DynamicResource VerBrush}” 保证金= “ 4” 填充= “ 0” HorizontalAlignment = “右” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 保证金= “ 4” 填充= “ 0” 高度= “ 40” 宽度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “1“ CornerRadius = ” 8“ 背景= ” {DynamicResource VerBrush}“ 保证金= “ 4” 填充= “ 0” 高度= “ 40” 宽度= “ 25” />
</ WrapPanel>
<WrapPanel x:Name = “” WrapPanel4“ 背景= ”白色“ 保证金= ” 0,8,8,8 “ Grid.Row = ” 1“ Grid.Column = ” 3“ Grid.RowSpan = ” 2“ 方向= ”垂直“ ItemWidth = ”“ {Binding SelectedItem.Content,ElementName = VerItemsWidth}” ItemHeight = “” {Binding SelectedItem.Content, ElementName = VerItemsHeight}” >
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius =“ 8” 背景= “ {DynamicResource VerBrush}” 保证金= “ 4” 宽度= “ 25” 高度= “ 40” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}“ 边距= ” 4“ 宽度= ” 25“ 高度= ” 50“ />
<Border BorderBrush = ”黑色“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= ”{DynamicResource VerBrush}“ 保证金= ” 4“ 宽度= ” 25“ 高度=“ 60” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” 宽度= “ 25” 高度= “ 70” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” 高度= “ 80” 宽度= “ 25” />
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius =“ 8” 背景= “ {DynamicResource VerBrush}” 边距= “ 4” 高度= “ 90” 宽度= “ 25” />
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource VerBrush}“ 保证金= ” 4“ 高度= ” 100“ 宽度= ” 25“ />
<Border BorderBrush = ”黑色“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= ”{DynamicResource VerBrush}“ 保证金= ” 4“ 高度= ” 140“ 宽度=“ 25” />
</ WrapPanel>
<StackPanel Margin = “ 8,0,8,8” Grid.Row = “ 4” Orientation = “ Horizontal” >
<TextBlock Text = “ Items:” VerticalAlignment = “” Center“ />
<TextBlock Text = “ Width” VerticalAlignment = “ Center” 边距= “ 4,2,0,0” FontSize = “ 10” />
<ComboBox x:Name = “ HorItemsWidth” 边距= “ 2,0,0,0” FontSize = “ 10” VerticalAlignment = “居中” >
<ComboBoxItem 内容= “自动” IsSelected = “ True” />
<ComboBoxItem Content = “ 20” />
<ComboBoxItem Content = “ 80” />
</ ComboBox>
<TextBlock Text = “ Height” VerticalAlignment = “” Center“页 边距= ” 4,2,0, 0“ FontSize = ” 10“ />
<ComboBox x:Name = ” HorItemsHeight“ 裕度= ” 2,0,0,0“ FontSize = ” 10“ VerticalAlignment = ” Center“ >
<ComboBoxItem Content = ” Auto“ IsSelected = “ True” />
<ComboBoxItem Content = “ 30”/>
<ComboBoxItem Content = “ 60” />
</ ComboBox>
</ StackPanel>
<StackPanel Margin = “ 8,0,8,8” Grid.Row = “ 4” Orientation = “ Horizontal” Grid.Column = “ 2 “ Grid.ColumnSpan = ” 3“ >
<TextBlock 文本= ”项目:“ VerticalAlignment = ”居中“ />
<TextBlock 文本= ”宽度“ VerticalAlignment = ”居中“页 边距= ” 4,2,0,0“ FontSize = ” 10“ />
<ComboBox x:Name = “ VerItemsWidth” 边距= “ 2,0,0,0” FontSize = “ 10” VerticalAlignment = “ Center” >
<ComboBoxItem Content = “ Auto” IsSelected = “ True” />
<ComboBoxItem Content = “ 20” />
<ComboBoxItem Content = “ 80” />
</ ComboBox>
<TextBlock 文本= “ Height” VerticalAlignment = “中心” 保证金= “ 4,2,0,0” FontSize = “ 10” />
<ComboBox x:Name = “ VerItemsHeight” 保证金= “ 2,0,0,0” FontSize = “ 10” VerticalAlignment = “ Center” >
<ComboBoxItem Content = “ Auto” IsSelected = “ True” />
<ComboBoxItem Content = “ 30” />
<ComboBoxItem Content = “ 60” />
</ ComboBox>
</ StackPanel>
</ Grid>
</pre>
![](https://img.haomeiwen.com/i20475064/2b510d09a1fd68e9.png)
码头面板
DockPanel是用于确定应用程序布局的最广泛使用的控件。它使用附加的属性DockPanel.Dock来确定每个包含的元素的位置。有效值为Top,Bottom,Left和Right。
如果未指定包含元素的高度或宽度,它将占用整个可用区域。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><Grid
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“
mc:Ignorable = ” d“
Background = ” LightGray“
TextElement。前景= “黑色”
边距= “ 10” HorizontalAlignment = “中心” VerticalAlignment = “中心” >
<Grid.Resources>
<LinearGradientBrush x:Key = “ BgBrush” StartPoint = “ 0,0” EndPoint = “ 1,1” >
<GradientStop Offset = “ 0” Color = “#FF9BDEFF” />
<GradientStop Offset = “ 1 “ Color = ”#FF69B5FF“ />
</ LinearGradientBrush>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height = “ Auto” />
<RowDefinition />
<RowDefinition Height = “ Auto” />
</Grid.RowDefinitions>
<StackPanel Orientation = “ Horizontal” HorizontalAlignment = “ Center” Margin = “ 0,8,0,0” >
<TextBlock Text = “ DockPanel大小:” />
<TextBlock Text = “” {Binding ActualWidth,ElementName = DockPanel}“ / >
<TextBlock Text = “ x” />
<TextBlock Text = “” {Binding ActualHeight,ElementName = DockPanel}“ />
</ StackPanel>
<DockPanel x:Name = ” DockPanel“ 背景= ” White“ 高度= ” 240“ 保证金= “ 8” Grid.Row = “ 1” 宽度= “ 380” LastChildFill = “ {绑定已检查,ElementName = LastChildFills}” >
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” DockPanel.Dock = “”顶部“ 保证金= ” 4“ 填充= “ 0” >
<网格>
<StackPanel Orientation = “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ Margin = ” 8“ >
<TextBlock Text = ”dock =“ />
<TextBlock Text =“ {Binding(DockPanel.Dock),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}” />
</ StackPanel>
</ Grid>
</ Border>
<Border BorderBrush = “ Black” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” DockPanel.Dock = “ Bottom” Margin = “ 4” Padding = “ 0” >
<Grid>
<StackPanel Orientation = “ Horizontal” HorizontalAlignment = “ Center” VerticalAlignment = “ Center ” Margin = “ 8” >
<TextBlock Text = “ dock =”/>
<TextBlock Text = “ {Binding(DockPanel.Dock),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}” />
</ StackPanel>
</ Grid>
</ Border>
<Border BorderBrush = “黑色“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= ” {DynamicResource BgBrush}“ 保证金= ” 4“ 填充= ” 0“ >
<Grid>
<StackPanel Orientation = ” Horizontal“ HorizontalAlignment = ” Center“ VerticalAlignment = ” Center“ Margin = “ 8” >
<TextBlock Text = “ dock =”/>
<TextBlock Text = “ {Binding(DockPanel.Dock),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}” />
</ StackPanel>
</ Grid>
</ Border>
<Border BorderBrush = “黑色“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= ” {DynamicResource BgBrush}“ DockPanel.Dock = ”“右” 保证金= “ 4” 填充= “ 0” >
<Grid>
<StackPanel Orientation = “ Horizontal” HorizontalAlignment = “中央” VerticalAlignment = “居中” 利润= “ 8” >
<TextBlock Text = “ dock =” />
<TextBlock Text = “” {Binding(DockPanel.Dock),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}“” />
</ StackPanel>
</ Grid>
</边框>
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” DockPanel.Dock = “顶部” 保证金= “ 4” 填充= “ 0” >
<网格>
<StackPanel 方向= “水平” HorizontalAlignment = “中心” VerticalAlignment = “中心” Margin = “ 8” >
<TextBlock Text = “ dock =” />
<TextBlock Text = “” {Binding(DockPanel.Dock),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“ />
</ StackPanel>
</ Grid>
</ Border>
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” DockPanel.Dock = “” {Binding SelectedItem.Content,ElementName = Positioning}“ 边距= “ 4” 填充= “ 0” >
<Grid>
<StackPanel HorizontalAlignment = “居中” VerticalAlignment = “居中”页 边距= “ 8” >
<TextBlock 文本= “最后一个孩子” FontWeight = “粗体” />
<StackPanel 方向= “水平” >
<TextBlock 文本= “ dock =” />
<TextBlock 文本= “ {绑定(DockPanel.Dock),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
</ StackPanel>
</ StackPanel>
</ Grid>
</ Border>
</ DockPanel>
<StackPanel Grid.Row = “ 2” 保证金= “ 8,0,8,8” 方向= “ Horizontal” >
<TextBlock 文字= “上一个孩子:” 边距= “ 0,0,16,0” VerticalAlignment = “中心” FontWeight = “粗体” />
<ComboBox x:Name = “定位” 边距= “ 0,0,4,0” VerticalAlignment = “居中” >
<ComboBoxItem 内容= “左” IsSelected = “真” />
<ComboBoxItem 内容= “右” />
<ComboBoxItem 内容= “顶部” />
<ComboBoxItem 内容= “底部” />
</ ComboBox>
<TextBlock Text = “ Positioning” Margin =“ 0,0,16,0” VerticalAlignment = “居中” />
<CheckBox x:Name = “ LastChildFills” Content = “填充剩余空间” IsChecked = “ False” VerticalAlignment = “居中” Margin = “ 0,0,8 ,0“ Foreground = ” Black“ />
</ StackPanel>
</ Grid>
</pre>
![](https://img.haomeiwen.com/i20475064/57b72bded1ce494d.png)
如图所示,需要在每个单独的元素上明确提及Dock属性。声明顺序也起着至关重要的作用。如果将连续两个元素的停靠设置为“顶部”,则意味着这些元素将垂直堆叠。
名为LastChildFill的属性可将剩余空间填充到最后一个元素中。如果不需要,可以将其设置为false。
格网
网格是功能最强大的面板之一。它可以用来形成一个填充可用空间的表。您可以使用属性RowDefinitions和ColumnDefinitions定义网格的行和列。大小的小区的属性高度和宽度的RowDefinition和ColumnDefinition分别被使用。有效值为:
- 自动:大小由放置在表格单元格中的元素确定。
- 星号:使用星号时,表示将使用比率进行测量。“ 2 *”表示“ 1 *”的两倍。因此,如果要以2:1的比例制作两列,则将宽度分别设置为“ 2 *”和“ 1 *”。默认值为“ 1 *”。
- 绝对:您还可以指定像素的高度和宽度的绝对值。
可以使用行的MinHeight / MaxHeight和列的MinWidth / MaxWidth来限制像元大小。这些属性仅允许使用绝对值。
要将元素放在表格单元格中,请使用附加的属性Grid.Row和Grid.Column。元素还可以分别使用附加的属性Grid.RowSpan和Grid.ColSpan跨越行和列的总数。
<pre style="box-sizing: inherit; overflow: auto; font-family: Consolas, "Courier New", Courier, monospace; font-size: 0.9em; background: rgb(244, 244, 244); border: 1px solid rgb(230, 230, 230); color: rgb(0, 0, 0); margin: 0px; padding: 0.25em;"><Grid
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“
mc:Ignorable = ” d“
Background = ” LightGray“
TextElement。前景= “黑色”
边距= “ 10” HorizontalAlignment = “中心” VerticalAlignment = “中心” >
<Grid.Resources>
<LinearGradientBrush x:Key = “ BgBrush” StartPoint = “ 0,0” EndPoint = “ 1,1” >
<GradientStop Offset = “ 0” Color = “#FF9BDEFF” />
<GradientStop Offset = “ 1 “ Color = ”#FF69B5FF“ />
</ LinearGradientBrush>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width = “自动” />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height = “ Auto” />
<RowDefinition Height = “ Auto” />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation = “ Horizontal” HorizontalAlignment = “ Center” 边距= “ 0,8,0,0” Grid.ColumnSpan = “ 2” >
<TextBlock Text = “网格大小:” />
<TextBlock Text = “” {Binding ActualWidth ,ElementName = Grid}“ />
<TextBlock Text = ” x“ />
<TextBlock Text = ”“ {Binding ActualHeight,ElementName = Grid}” />
</ StackPanel>
<Grid Grid.Column = “ 1” Grid.Row = “ 1” 保证金= “ 8,8,8,0“ >
<Grid.ColumnDefinitions>
<ColumnDefinition Width = “ 100” />
<ColumnDefinition Width = “ 87” />
<ColumnDefinition Width = “ *” />
<ColumnDefinition Width = “ 2 *” />
</Grid.ColumnDefinitions>
<TextBlock Text = “ 100” HorizontalAlignment = “ Center” VerticalAlignment = “ Center” />
<TextBlock 文本= “ Auto” HorizontalAlignment = “ Center” VerticalAlignment = “ Center” Grid.Column = “ 1” />
<TextBlock Text = “ *” HorizontalAlignment = “ Center” VerticalAlignment = “ Center” Grid.Column = “ 2” />
<TextBlock Text = “ 2 *” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ Grid.Column = ” 3“ />
</ Grid>
<Grid Grid.Column = “ 0” Grid.Row = “ 2” 保证金= “ 8,8,0,8” >
<Grid.RowDefinitions>
<RowDefinition Height = “ 140” />
<RowDefinition Height = “ 90” />
<RowDefinition Height = “” *“ />
<RowDefinition Height = ” 2 *“ />
</Grid.RowDefinitions>
<TextBlock Text = “ 140” HorizontalAlignment = “ Center” VerticalAlignment = “ Center” />
<TextBlock Text = “ Auto” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ Grid.Row = ” 1“ / >
<TextBlock Text = “ 0.333 *” HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ Grid.Row = ” 2“ />
<TextBlock Text = ” 0.667 *“ HorizontalAlignment = “居中” VerticalAlignment = “居中” Grid.Row =“ 3” />
</ Grid>
<Grid x:Name = “ Grid” 宽度= “ 500” 高度= “ 400” Grid.Row = “ 2” 背景= “白色” 边距= “ 8” Grid.Column = “ 1“ >
<Grid.ColumnDefinitions>
<ColumnDefinition Width = ” 100“ />
<ColumnDefinition Width = ” Auto“ />
<ColumnDefinition Width = ” *“ />
<ColumnDefinition Width = ” 2 *“ />
</ Grid。ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height = “ 140”/>
<RowDefinition Height = “ Auto” />
<RowDefinition Height = “ 0.3333 *” />
<RowDefinition Height = “ 0.6667 *” />
</Grid.RowDefinitions>
<Border BorderBrush = “ Black” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” 保证金= “ 4” 填充= “ 0” >
<StackPanel HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ Margin = “ 8” >
<StackPanel Orientation = “水平” 保证金= “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” row =“ />
<TextBlock Text = ”“ {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border }}}“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ col =” />
<TextBlock Text = “{Binding(Grid.Column),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“/>
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” rowSpan =“ />
<TextBlock Text = ”“ {Binding(Grid.RowSpan ),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“ /> />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
</ StackPanel>
</ StackPanel>
</ Border>
<Border BorderBrush = ” Black“ BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” Grid.Column = “ 1” 保证金= “ 4” 填充= “ 0” >
<StackPanel HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ Margin = ” 8英寸>
<StackPanel 方向= “水平” 边距=“ 0” HorizontalAlignment = “左” VerticalAlignment = “” Center“ >
<TextBlock Text = ” row =“ />
<TextBlock Text = ”“ {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}} }“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ col =” />
<TextBlock Text = “” {绑定(网格。列),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” rowSpan =“ />
<TextBlock Text = ”“ {Binding(Grid.RowSpan), RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
</ StackPanel>
</ StackPanel>
</ Border>
<Border BorderBrush = ”黑色“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= ” {DynamicResource BgBrush}“ Grid.Column = ” 2“ 保证金= ” 4“ 填充= ” 0“ >
<StackPanel HorizontalAlignment = ” Center“ VerticalAlignment = ”“ Center” 利润= “ 8” >
<StackPanel 方向= “水平” 边距= “ 0” HorizontalAlignment = “左” VerticalAlignment = “居中” >
<TextBlock Text = “ row =” />
<TextBlock Text = “” {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}“ / >
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” col =“ />
<TextBlock Text = ”“ {Binding(Grid.Column) ,RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “ Center” >
<TextBlock Text = “ rowSpan =” />
<TextBlock Text = “” {Binding(Grid.RowSpan),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” 保证金= “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “ Center” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text =“ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}” />
</ StackPanel>
</ StackPanel>
</ Border>
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” Grid.Column = “ 3” 保证金= “ 4” 填充= “ 0” >
<StackPanel HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ 保证金= ” 8“ >
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment =“左” VerticalAlignment = “中心” >
<TextBlock 文本= “” row =“ />
<TextBlock 文本= ”“ {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}”“ />
< / StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” col =“ />
<TextBlock Text = ”“ {Binding(Grid.Column),RelativeSource = {RelativeSource AncestorType = {x:键入Border}}}“ />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “ Center” >
<TextBlock Text = “ rowSpan =” />
<TextBlock Text = “” {Binding(Grid.RowSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“ /> />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ” = “ Center” >
<TextBlock Text = “” colSpan =“/>
<TextBlock Text =“ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}” />
</ StackPanel>
</ StackPanel>
</ Border>
<Border BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” 保证金= “ 4” 填充= “ 0” Grid.Row = “ 1” Grid.ColumnSpan = “ 2” >
<StackPanel HorizontalAlignment = “ Center” VerticalAlignment = “ Center” 保证金= “ 8”>
<StackPanel 方向= “水平” 边距=“ 0” HorizontalAlignment = “左” VerticalAlignment = “” Center“ >
<TextBlock Text = ” row =“ />
<TextBlock Text = ”“ {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}} }“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ col =” />
<TextBlock Text = “” {绑定(网格。列),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” rowSpan =“ />
<TextBlock Text = ”“ {Binding(Grid.RowSpan), RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
</ StackPanel>
</ StackPanel>
</ Border>
<Border BorderBrush = ” Black“ BorderThickness = ” 1“ CornerRadius = ” 8“ 背景= ” {DynamicResource BgBrush}“ Grid.Column = ” 2“页 边距= ” 4“ 填充= ” 0“ Grid.Row = ” 1“ >
<StackPanel HorizontalAlignment = ” Center“ VerticalAlignment = ”中心“ 保证金= ”8“ >
<StackPanel Orientation = ”水平“ 保证金= “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” row =“ />
<TextBlock Text = ”“ {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border }}}“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ col =” />
<TextBlock Text = “{Binding(Grid.Column),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“/>
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” rowSpan =“ />
<TextBlock Text = ”“ {Binding(Grid.RowSpan ),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“ /> />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
</ StackPanel>
</ StackPanel>
</ Border>
<Border BorderBrush = ” Black“ BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” Grid.Column = “ 3” 保证金= “ 4” 填充= “ 0” Grid.Row = “ 1” Grid.RowSpan = “ 2” >
< StackPanel HorizontalAlignment = “居中” VerticalAlignment = “居中” 利润= “ 8” >
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “ Center” >
<TextBlock Text = “ row =” />
<TextBlock Text = “” {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:类型边框}}}“” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ”col =“ />
<TextBlock Text =“ {Binding(Grid.Column),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “”中心” >
<TextBlock Text = “ rowSpan =” />
<TextBlock Text = “” {Binding(Grid.RowSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“” />
</ StackPanel>
<StackPanel 方向= “水平” 保证金= “ 0” HorizontalAlignment = “左” VerticalAlignment = “中心” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “” {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}“ />
</ StackPanel>
</ StackPanel>
</边框>
<边框 BorderBrush = “黑色” BorderThickness = “ 1” CornerRadius = “ 8” 背景= “ {DynamicResource BgBrush}” 保证金= “ 4” 填充= “ 0” Grid.Row = “ 2” Grid.ColumnSpan = “ 3 “ >
<StackPanel HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ 边距=“ 8,4,8,3” 方向= “水平” >
<StackPanel 方向= “垂直” 保证金= “ 10,0,0,0” >
<StackPanel 方向= “水平” 保证金= “ 0” HorizontalAlignment = “左“ VerticalAlignment = ” Center“ >
<TextBlock Text = ” row =“ />
<TextBlock Text = ”“ {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
</ StackPanel >
<StackPanel 方向= “水平“ 保证金= ” 0“ HorizontalAlignment = ”左“ VerticalAlignment = “居中” >
<TextBlock Text = “ col =” />
<TextBlock Text = “” {Binding(Grid.Column),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}“ />
</ StackPanel>
</ StackPanel>
<StackPanel Orientation = “ Vertical” Margin = “ 10,0,0,0” >
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “ Center” >
<TextBlock Text = ”rowSpan =“ />
<TextBlock Text =“ {Binding(Grid.RowSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}” />
</ StackPanel>
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “”中心” >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “” {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}}“ />
</ StackPanel>
</ StackPanel >
</ StackPanel>
</ Border>
<Border BorderBrush = “黑色“ BorderThickness = ” 1“ CornerRadius =“ 8” 背景= “ {DynamicResource BgBrush}” 保证金= “ 4” 填充= “ 0” Grid.Row = “ 3” Grid.ColumnSpan = “ 4” >
<StackPanel HorizontalAlignment = “ Center” VerticalAlignment = “” Center“ 利润= “ 8,4,8,3” 方向= “水平” >
<StackPanel 方向= “垂直” 保证金= “ 10,0,0,0” >
<StackPanel 方向= “水平” 保证金= “ 0” HorizontalAlignment = “左” VerticalAlignment = “中心” >
<TextBlock Text = “ row =” />
<TextBlock Text = “” {Binding(Grid.Row),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“” />
</ StackPanel>
<StackPanel Orientation = “水平“ 保证金= ” 0“ HorizontalAlignment = ”左“ VerticalAlignment = ”“ Center” >
<TextBlock Text = “ col =” />
<TextBlock Text = “” {Binding(Grid.Column),RelativeSource = {RelativeSource AncestorType = {x:Type边框}}}“ />
</ StackPanel>
</ StackPanel>
<StackPanel Orientation = “垂直”页 边距=“ 10,0,0,0” >
<StackPanel Orientation = “ Horizontal” Margin = “ 0” HorizontalAlignment = “ Left” VerticalAlignment = “” Center“ >
<TextBlock Text = ” rowSpan =“ />
<TextBlock Text = ”“ { (Grid.RowSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}“ />
</ StackPanel>
<StackPanel Orientation = ” Horizontal“ Margin = ” 0“ HorizontalAlignment = ” Left“ VerticalAlignment = ” Center“ >
<TextBlock Text = “ colSpan =” />
<TextBlock Text = “ {Binding(Grid.ColumnSpan),RelativeSource = {RelativeSource AncestorType = {x:Type Border}}}”“ />
</ StackPanel>
</ StackPanel>
</ StackPanel>
</ Border>
</ Grid>
</网格>
</pre>
![](https://img.haomeiwen.com/i20475064/dd0a22e791368cf9.png)