Over Killer
Over Killer

Reputation: 513

Control Template: "Content is set more than once"

I'm trying to create a Control Template for button. I can add colors and text but not edit transitions of button because of this error: 'System.Windows.Controls.Button.Content' property has already been set and can be set only once. But I set content once:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Button" x:Name="redTitle" x:Key="redTitle">
        <!--Set to true to not get any properties from the themes.-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">

                    <Button Content="{TemplateBinding Content}" BorderBrush="Red" Foreground="White">
                        <VisualStateGroup Name="States">
                            <VisualStateGroup.Transitions>
                                <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.01"></VisualTransition>
                            </VisualStateGroup.Transitions>
                        </VisualStateGroup>
                        <Button.Background>
                            <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                <GradientStop Color="Red"/>
                                <GradientStop Color="Red" Offset="1"/>
                            </LinearGradientBrush>
                        </Button.Background>
                    </Button>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
    </Style>

</ResourceDictionary>

Where is the error?

Upvotes: 0

Views: 415

Answers (1)

Mike Strobel
Mike Strobel

Reputation: 25623

You need to wrap the <VisualStateGroup> element in <VisualStateManager.VisualStateGroups>. The error is telling you that you assigned the button's content with both the Content attribute and implicitly by placing <VisualStateGroup> as the button's immediate child. You meant to place the latter in a property setter.

Upvotes: 2

Related Questions