Wpf 在嵌套样式中设置RenderTransform

Wpf 在嵌套样式中设置RenderTransform,wpf,xaml,.net-3.5,styling,Wpf,Xaml,.net 3.5,Styling,我在Windows8上使用.NET3.5,带有默认的Aero主题 这本应该是一个答案,但它没有我想象的那么容易。我正试图: 缩放复选框控件中的框 在样式中,以便我可以将更改应用于所有复选框(或仅部分复选框) 与文本无关,无需补偿 我有一个用户控件,使用以下资源: <UserControl.Resources> <ResourceDictionary> <!-- ... --> <ResourceDictionar

我在Windows8上使用.NET3.5,带有默认的Aero主题

这本应该是一个答案,但它没有我想象的那么容易。我正试图:

  • 缩放复选框控件中的框
  • 在样式中,以便我可以将更改应用于所有复选框(或仅部分复选框)
  • 与文本无关,无需补偿
  • 我有一个用户控件,使用以下资源:

    <UserControl.Resources>
        <ResourceDictionary>
            <!-- ... -->
    
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/CheckBoxStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    

    我找到了一个解决方案,尽管它并不完美。一个更好的答案仍然会被接受

    我曾经确定我关心的元素已经是ContentPresenter。它包含一个文本块,但由于某些原因无法设置样式(它显示在Snoop层次结构中的括号中)。下面是我得到的CheckBoxStyle.xaml

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework">
        <Style TargetType="{x:Type CheckBox}">
            <Style.Resources>
                <Style TargetType="{x:Type ContentControl}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ContentControl}">
                                <ContentPresenter>
                                    <ContentPresenter.LayoutTransform>
                                        <ScaleTransform ScaleX="0.5" ScaleY="0.5" />
                                    </ContentPresenter.LayoutTransform>
                                </ContentPresenter>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <ScaleTransform ScaleX="2" ScaleY="2"/>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
    
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework">
        <Style TargetType="{x:Type CheckBox}">
            <Style.Resources>
                <Style TargetType="{x:Type ContentPresenter}">
                    <Setter Property="LayoutTransform">
                        <Setter.Value>
                            <ScaleTransform ScaleX="0.5" ScaleY="0.5" />
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <ScaleTransform ScaleX="2" ScaleY="2"/>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
    
    
    
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework">
        <Style TargetType="{x:Type CheckBox}">
            <Style.Resources>
                <Style TargetType="{x:Type ContentPresenter}">
                    <Setter Property="LayoutTransform">
                        <Setter.Value>
                            <ScaleTransform ScaleX="0.5" ScaleY="0.5" />
                        </Setter.Value>
                    </Setter>
                </Style>
            </Style.Resources>
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <ScaleTransform ScaleX="2" ScaleY="2"/>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>