Is there a way to edit a control's template based on the default template?

Posted by Adam S on Stack Overflow See other posts from Stack Overflow or by Adam S
Published on 2010-05-25T19:00:48Z Indexed on 2010/05/25 19:21 UTC
Read the original article Hit count: 407

Filed under:
|
|
|

I'm trying to make just a few minor tweaks to the default template of a checkbox. Now I understand how to make a new template from scratch, but this I do not know. I did manage to (I think?) extract the default template via the method here.

And it spat out:

    <ControlTemplate TargetType="CheckBox" 
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                     xmlns:s="clr-namespace:System;assembly=mscorlib" 
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                     xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna">
        <BulletDecorator Background="#00FFFFFF" SnapsToDevicePixels="True">
            <BulletDecorator.Bullet>
                <mwt:BulletChrome Background="{TemplateBinding Panel.Background}" 
                                  BorderBrush="{TemplateBinding Border.BorderBrush}" 
                                  BorderThickness="{TemplateBinding Border.BorderThickness}" 
                                  RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" 
                                  RenderPressed="{TemplateBinding ButtonBase.IsPressed}" 
                                  IsChecked="{TemplateBinding ToggleButton.IsChecked}" />
            </BulletDecorator.Bullet>
            <ContentPresenter RecognizesAccessKey="True" 
                              Content="{TemplateBinding ContentControl.Content}" 
                              ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" 
                              ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" 
                              Margin="{TemplateBinding Control.Padding}" 
                              HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" 
                              VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" 
                              SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </BulletDecorator>
        <ControlTemplate.Triggers>
            <Trigger Property="ContentControl.HasContent">
                <Setter Property="FrameworkElement.FocusVisualStyle">
                    <Setter.Value>
                        <Style TargetType="IFrameworkInputElement">
                            <Style.Resources>
                                <ResourceDictionary />
                            </Style.Resources>
                            <Setter Property="Control.Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Rectangle Stroke="#FF000000" 
                                                   StrokeThickness="1" 
                                                   StrokeDashArray="1 2" 
                                                   Margin="14,0,0,0" 
                                                   SnapsToDevicePixels="True" />
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Setter.Value>
                </Setter>
                <Setter Property="Control.Padding">
                    <Setter.Value>
                        <Thickness>2,0,0,0</Thickness>
                    </Setter.Value>
                </Setter>
                <Trigger.Value>
                    <s:Boolean>True</s:Boolean>
                </Trigger.Value>
            </Trigger>
            <Trigger Property="UIElement.IsEnabled">
                <Setter Property="TextElement.Foreground">
                    <Setter.Value>
                        <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                    </Setter.Value>
                </Setter>
                <Trigger.Value>
                    <s:Boolean>False</s:Boolean>
                </Trigger.Value>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

Okay, sure, looks just fine I guess. I don't have enough experience to know if that looks like it's right or not. Now, I get two errors:

Assembly 'PresentationFramework.Luna' was not found. Verify that you are not missing an assembly reference. Also, verify that your project and all referenced assemblies have been built.

and

The type 'mwt:BulletChrome' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

Now I'm wondering, how can I resolve these errors so that I can actually start working on the template? Is there a better way of going about this? My boss wants a three-state checkbox with a red square instead of green, and he won't take no for an answer.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf