wpf*给了几个内置的构造,如StackPanel,Grid,DockPanel,Canvas等,其实也可以担任自Panel并重写MeasureOverride和ArrangeOverride要领自界说一个面板中的元素构造格局,,例子:
窗口缩小后:
图中最外面是一个自界说面板StairPanel, 此中1,2,3处分袂为三个子元素,2为按钮,1和3又是StairPanel, 此中分袂又有四个按钮,仍然是阶梯状构造。
当窗口巨细转变后是自适应的。
xaml:
<Window x:Class="WpfApplication1._24.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:WpfApplication1._24"
mc:Ignorable="d"
Title="Window1">
<Window.Resources>
<Style x:Key="Style2" TargetType="{x:Type Button}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF1467C2" Offset="0"/>
<GradientStop Color="#FFAAC5E2" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="Style1" TargetType="{x:Type local:StairPanel}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFDD8116" Offset="0"/>
<GradientStop Color="#FF0DBD2F" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="Style3" TargetType="{x:Type Button}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFDD8116" Offset="0"/>
<GradientStop Color="#FF0DBD2F" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<local:StairPanel>
<local:StairPanel>
<Button x:Name="Button1_1" Content="Button1.1"/>
<Button x:Name="Button1_2" Content="Button1.2"/>
<Button x:Name="Button1_3" Content="Button1.3"/>
<Button x:Name="Button1_4" Content="Button1.4"/>
</local:StairPanel>
<Button x:Name="Button2" Content="Button2" FontSize="22"/>
<local:StairPanel>
<Button x:Name="Button3_1" Content="Button3.1"/>
<Button x:Name="Button3_2" Content="Button3.2"/>
<Button x:Name="Button3_3" Content="Button3.3"/>
<Button x:Name="Button3_4" Content="Button3.4"/>
</local:StairPanel>
</local:StairPanel>
</Window>
cs: