是否有一个标准的WPF样式表可以实现“微软”风格?

5

有没有适用于任何窗口的精美样式表(以及其使用指南),以便给它一个合适的“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>

它使窗口呈现出这样的外观:

虽然不是完美的,但应用样式比没有样式时要好得多。

1个回答

2
您可以在WPF Toolkit页面上找到微软提供的7种WPF主题。 点击链接

1
谢谢,但这不是我需要的。我需要所有控件的适当大小和边距,并且该页面上的主题仅更改颜色。 - Mikhail Orlov
你找到解决方案了吗?我也很感兴趣。对于CSS,有几种常见的样式表可用于最佳实践布局。 - Bent Rasmussen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接