- App.xaml
添加静态资源 样式,LabelStyle,BorderStyle
<Application.Resources>
<Style x:Key="LabelStyle" TargetType="Label">
<Setter Property="FontSize" Value="14"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="AliceBlue"/>
</Style>
<Style x:Key="BorderStyle" TargetType="Border">
<Setter Property="Height" Value="35"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="AliceBlue"/>
</Style>
</Application.Resources>
- MainWindow.xaml
设置 Grid 的列,具体不清楚,
貌似给第一个 Rectangle 设了 2 列,后两个 Rectangle 在第一列,frame 在第二列;
其中设置了 StackPanel 的资源,指定了 Button 的样式;
<Window x:Class="ch01.MainWindow"
...
Title="第一章示例" Height="500" Width="700"
Background="#FFF0F9D8" WindowStartupLocation="CenterScreen">
<Grid Margin="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.ColumnSpan="2" Fill="White"
RadiusX="14" RadiusY="14" Stroke="Red" StrokeDashArray="3"/>
<Rectangle Grid.Column="0" Margin="7" Fill="#FFF0F9D8"
RadiusX="10" RadiusY="10" Stroke="Black" StrokeDashArray="3"/>
<Rectangle Grid.Column="0" Margin="20" Fill="AliceBlue" Stroke="Blue"/>
<ScrollViewer Grid.Column="0" Margin="22">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="5 10 5 0"/>
<Setter Property="Padding" Value="15 0 15 0"/>
<Setter Property="FontSize" Value="10"/>
<EventSetter Event="Click" Handler="button_Click"/>
</Style>
</StackPanel.Resources>
<Button Content="例1" Tag="/Examples/DnsExamplePage.xaml"/>
<Button Content="例2" Tag="/Examples/NetworkInterfacePage.xaml"/>