【问题标题】:Is there a standard WPF stylesheet for a "Microsoft" look?是否有用于“Microsoft”外观的标准 WPF 样式表?
【发布时间】:2018-06-21 23:17:32
【问题描述】:

是否有一些精美的样式表(及其使用指南)可以应用于任何窗口以使其具有适当的“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>

它使窗口看起来像这样:

它并不完美,但比没有应用样式时要好得多。

【问题讨论】:

    标签: wpf wpf-controls


    【解决方案1】:

    您可以在 WPF Toolkit page 上找到 Microsoft 的 7 个 WPF 主题。

    【讨论】:

    • 谢谢,但这不是我需要的。我需要为所有控件提供适当的大小和边距,并且该页面上的主题只会改变颜色。
    • 您找到解决方案了吗?我也对这个感兴趣。对于 CSS,有几种常见的样式表可用于最佳实践布局。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-02
    相关资源
    最近更新 更多