【问题标题】:Default ControlTemplate for CheckBoxCheckBox 的默认 ControlTemplate
【发布时间】:2012-10-18 20:53:23
【问题描述】:

我找不到CheckBox 的默认 WPF ControlTemplate。有谁知道如何找到它?我只能找到SilverLight default checkbox template on MSDN

MSDN has a custom control template for the WPF checkbox 使用 X 代替复选标记的示例。我正在专门寻找 WPF 标配的默认 复选标记样式 - 我只是找不到它的 XAML。

我也有tried saving the template using XamlWriter to no availDownloading the Simple Styles template from WPF Control Templates sample 也只是使用 X 而不是经典的复选标记。

【问题讨论】:

  • 你有 Expression Blend 吗?如果是这样的话,一般来说与模板交互会更容易。
  • 否 - 很遗憾,我无法访问 Expression。

标签: wpf xaml styles wpf-controls controltemplate


【解决方案1】:

我还没有看到任何其他主题的默认样式,但 Classic 可在线获得,但如果您碰巧找到它们,请在此处回帖 :) 我认为 MSDN 上的模板通常是 经典主题。

你可以使用Expression Blend来获取它,你可以下载一个trial here
选择CheckBox,转到对象 -> 编辑样式 -> 编辑副本。

假设你喜欢 windows 7 (aero) 风格,这里是

<SolidColorBrush x:Key="CheckBoxFillNormal" Color="#F4F4F4"/>
<SolidColorBrush x:Key="CheckBoxStroke" Color="#8E8F8F"/>
<Style x:Key="EmptyCheckBoxFocusVisual">
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>
                <Rectangle Margin="1" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="CheckRadioFocusVisual">
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>
                <Rectangle Margin="14,0,0,0" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background" Value="{StaticResource CheckBoxFillNormal}"/>
    <Setter Property="BorderBrush" Value="{StaticResource CheckBoxStroke}"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource EmptyCheckBoxFocusVisual}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type CheckBox}">
                <BulletDecorator Background="Transparent" SnapsToDevicePixels="true">
                    <BulletDecorator.Bullet>
                        <Microsoft_Windows_Themes:BulletChrome BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" IsChecked="{TemplateBinding IsChecked}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}"/>
                    </BulletDecorator.Bullet>
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </BulletDecorator>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasContent" Value="true">
                        <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                        <Setter Property="Padding" Value="4,0,0,0"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

【讨论】:

  • 太棒了...你为我节省了几个小时。我必须记住 Blend 技巧以供将来参考。
  • Vs2012 现在还包括“编辑副本”。
  • @AlSki 很棒的建议 - 我有 VS 2012 并且可以verify that Edit Template -> Edit a Copy has been added。这摇滚 - 无需表达许可证!输出与上面通过表达式生成的相同。仅了解工具功能就可以节省大量时间。
【解决方案2】:

获取所有 WPF 控件控件模板的另一种方法是使用这个奇妙的应用程序:http://www.sellsbrothers.com/posts/details/2091

【讨论】:

  • 这很有帮助,但它创建的模板副本不如 Blend 或 VS 2012 中的功能那么好。
  • 从未尝试过 Blend/VS2012 功能,但我会检查一下!感谢您的输入:)
猜你喜欢
  • 1970-01-01
  • 2013-05-23
  • 2012-04-26
  • 2015-02-28
  • 2019-01-22
  • 1970-01-01
  • 2021-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多