locked
Inheritng control template

    Question

  • Hi there,

    I have a working control template that I'm trying to inherit from in order to reduce XAML complexity but I can't work out how to override some of the properties...

        <Style x:Name="BrowseButtonBase" TargetType="Button">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid Name="RootFrame">
    
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootFrameScaleTransform"
                                                    Storyboard.TargetProperty="ScaleX">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootFrameScaleTransform"
                                                    Storyboard.TargetProperty="ScaleY">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="1" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootFrameScaleTransform"
                                                    Storyboard.TargetProperty="ScaleX">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="0.9" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootFrameScaleTransform"
                                                    Storyboard.TargetProperty="ScaleY">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="0.9" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootFrameScaleTransform"
                                                    Storyboard.TargetProperty="ScaleX">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="1.1" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootFrameScaleTransform"
                                                    Storyboard.TargetProperty="ScaleY">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="1.1" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
    
                            <Grid.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform x:Name="RootFrameScaleTransform"
                                                    ScaleX="1"
                                                    ScaleY="1"
                                                    CenterX="128"
                                                    CenterY="128" />
                                </TransformGroup>
                            </Grid.RenderTransform>
    
                            <Grid.Background>
                                <SolidColorBrush x:Name="ButtonBackgroundBrush" Color="Black" />
                            </Grid.Background>
                            <TextBlock x:Name="ButtonLabel" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
                            <Image x:Name="ButtonBackgroundImage" Source="" Opacity="0.1" />
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="FontFamily" Value="Arial" />
            <Setter Property="FontSize" Value="50" />
            <Setter Property="BorderThickness" Value="2" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <SolidColorBrush x:Name="ButtonBorderBrush" Color="White"/>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Name="TestButtonStyle" TargetType="Button" BasedOn="{StaticResource BrowseButtonBase}">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid Name="RootFrame">
                            <Grid.Background>
                                <SolidColorBrush x:Name="ButtonBackgroundBrush" Color="{StaticResource YearsAccentColour}" />
                            </Grid.Background>
                            <TextBlock x:Name="ButtonLabel" Text="{Binding}" />
                            <Image x:Name="ButtonBackgroundImage" Source="Assets/yearsbuttonimage.jpg" Opacity="0.1" />
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <SolidColorBrush x:Name="ButtonBorderBrush" Color="{StaticResource YearsAccentColour}"/>
                </Setter.Value>
            </Setter>
        </Style>

    The base style is BrowseButtonBase for which I've named a few controls I'd like to modify the properties of.

    Any idea what I'm doing wrong?


    Somewhere out there...

    Saturday, April 5, 2014 9:13 AM

All replies

  • Sorry, I don't understand your question.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, April 7, 2014 7:23 PM
    Moderator