有没有适用于任何窗口的精美样式表(以及其使用指南),以便给它一个合适的“Microsoft”外观?
在我的情况/示例中,我有一个简单的窗口:
<Window x:Class="WPFTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<GroupBox Header="My checkboxes">
<StackPanel >
<CheckBox>First</CheckBox>
<CheckBox>Second</CheckBox>
<CheckBox>Third</CheckBox>
</StackPanel>
</GroupBox>
<StackPanel Grid.Row="1" Grid.ColumnSpan="2"
Orientation="Horizontal"
HorizontalAlignment="Right">
<Button>OK</Button>
<Button>Cancel</Button>
</StackPanel>
</Grid>
</Window>
以下是示例效果:
我可以将样式分为以下几组:
<Window.Resources>
<Style TargetType="CheckBox">
<Setter Property="Margin" Value="0,8,0,0"/>
</Style>
<Style TargetType="Grid">
<Setter Property="Margin" Value="8"/>
</Style>
<Style TargetType="StackPanel">
<Setter Property="Margin" Value="0"/>
</Style>
<Style TargetType="GroupBox">
<Setter Property="Padding" Value="8"/>
</Style>
<Style TargetType="Button">
<Setter Property="Margin" Value="8,0,0,0"/>
<Setter Property="Padding" Value="8"/>
<Setter Property="MinWidth" Value="70"/>
</Style>
</Window.Resources>
随着第一个复选框的更改:
<CheckBox Margin="0">First</CheckBox>
它使窗口呈现出这样的外观:
虽然不是完美的,但应用样式比没有样式时要好得多。