Setting RenderTransform in Nested Style

I am using .Net 3.5 on Windows 8 with the default Aero theme.

This was supposed to be the answer to the Scale Checkbox without scaling the content , but it doesn't work as easily as I expected. I'm trying to:

  • scale the box in the checkbox control
  • in style so I can apply the change to all checkboxes (or just some)
  • regardless of its text, without the need to compensate.

I have a UserControl with these resources:

<UserControl.Resources>
    <ResourceDictionary>
        <!-- ... -->

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

      

Resources /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 BulletDecorator}">
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX="2" ScaleY="2"/>
                    </Setter.Value>
                </Setter>
            </Style>
        </Style.Resources>
    </Style>
</ResourceDictionary>

      

Namespace in case I agree to need to know what BulletDecorator is. primitives

I found BulletDecorator in the Aero theme for .Net 3.5 from here , behind the "Default WPF Themes" link, per this answer .

I don't see any difference in the sizes of my checkboxes. I don't think I grabbed the wrong element type from the theme, but what else could be going on?

Edit 1:

The BulletDecorator still contains the contents of the checkbox, so I tried to drop requirement # 3. Now I have a huge box and huge text, and I want to make the text smaller. Here is 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>

      

+3


source to share


1 answer


I found a solution, although not perfect. The best answer will be accepted.

I used Snoop to determine that the element I'm linked to is already a ContentPresenter. It contains a TextBlock, but cannot be styled for some reason (and is shown in parentheses in the Snoop hierarchy). This is where I got 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 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>

      

+5


source







All Articles