Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:28:34+00:00 2026-06-11T04:28:34+00:00

I’ve got the following base Style in XAML and I need to create a

  • 0

I’ve got the following base Style in XAML and I need to create a few new styles based on it with only 1 property different in each new style.

<UserControl.Resources>
<Style x:Key="BaseButtonStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Background" Value="{StaticResource Button.Background}"/>
            <Setter Property="BorderBrush" Value="{StaticResource Button.BorderBrush}"/>
            <Setter Property="Foreground" Value="{StaticResource Button.Foreground}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="10,1,10,1"/>
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ButtonBase}">
                        <Grid x:Name="Root" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <Grid x:Name="FocusState" Opacity="0">
                                <Border CornerRadius="4" Style="{StaticResource FocusTemplate}"/>
                            </Grid>
                            <Grid x:Name="DefaultState">
                                <Border Background="{StaticResource Button.DefaultState.Border1}"
                                    Padding="1" CornerRadius="3">
                                    <Border Background="{StaticResource Button.DefaultState.Border2}"
                                        Padding="1" CornerRadius="2">
                                    </Border>
                                </Border>
                            </Grid>
                            <Grid x:Name="HoverState" Opacity="0">
                                <Border Background="{StaticResource Button.HoverState.Border1}"
                                    Padding="1" CornerRadius="3">
                                    <Grid>
                                        <Border Background="{StaticResource Button.HoverState.Border2}"
                                            Padding="1" CornerRadius="2">
                                            <Border Background="{StaticResource Button.HoverState.Border3}"
                                                CornerRadius="1"/>
                                        </Border>
                                        <Border>
                                            <Border.Background>
                                                <RadialGradientBrush>
                                                    <RadialGradientBrush.RelativeTransform>
                                                        <TranslateTransform X="0" Y="0.5"/>
                                                    </RadialGradientBrush.RelativeTransform>
                                                    <GradientStop Color="#00FFFFFF" Offset="1"/>
                                                    <GradientStop Color="#BFFFFFFF" Offset="0"/>
                                                </RadialGradientBrush>
                                            </Border.Background>
                                        </Border>
                                    </Grid>
                                </Border>
                            </Grid>
                            <Grid x:Name="PressedState" Opacity="0">
                                <Border Background="{StaticResource Button.PressedState.Border1}"
                                    Padding="1" CornerRadius="3">
                                    <Border Background="{StaticResource Button.PressedState.Border2}"
                                        Padding="1" CornerRadius="2">
                                        <Border Background="{StaticResource Button.PressedState.Border3}"
                                            CornerRadius="1"/>
                                    </Border>
                                </Border>
                            </Grid>
                            <Grid x:Name="CheckedState" Opacity="0">
                                <Border Background="{StaticResource Button.CheckedState.Border1}"
                                    Padding="1" CornerRadius="3">
                                    <Border Background="{StaticResource Button.CheckedState.Border2}"
                                        Padding="1" CornerRadius="2">
                                        <Border Background="{StaticResource Button.CheckedState.Border3}"
                                            CornerRadius="1"/>
                                    </Border>
                                </Border>
                            </Grid>
                            <Grid Margin="2">
                                <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Grid>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="DefaultState" Property="Opacity" Value="0"/>
                                <Setter TargetName="HoverState" Property="Opacity" Value="1"/>
                                <Setter TargetName="PressedState" Property="Opacity" Value="0"/>
                                <Setter TargetName="CheckedState" Property="Opacity" Value="0"/>
                                <Setter Property="Foreground"
                                    Value="{StaticResource Button.Foreground}"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="DefaultState" Property="Opacity" Value="0"/>
                                <Setter TargetName="HoverState" Property="Opacity" Value="0"/>
                                <Setter TargetName="PressedState" Property="Opacity" Value="1"/>
                                <Setter TargetName="CheckedState" Property="Opacity" Value="0"/>
                                <Setter Property="Foreground"
                                    Value="{StaticResource Button.Foreground}"/>
                            </Trigger>
                            <Trigger Property="ToggleButton.IsChecked" Value="True">
                                <Setter TargetName="DefaultState" Property="Opacity" Value="0"/>
                                <Setter TargetName="HoverState" Property="Opacity" Value="0"/>
                                <Setter TargetName="PressedState" Property="Opacity" Value="0"/>
                                <Setter TargetName="CheckedState" Property="Opacity" Value="1"/>
                                <Setter Property="Foreground"
                                    Value="{StaticResource Button.Foreground}"/>
                            </Trigger>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter TargetName="FocusState" Property="Opacity" Value="1"/>
                            </Trigger>
                            <Trigger Property="Button.IsDefaulted" Value="True">
                                <Setter TargetName="FocusState" Property="Opacity" Value="1"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="Root" Property="Opacity" Value="0.35"/>
                                <Setter Property="Foreground"
                                    Value="{StaticResource Button.Foreground}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
</Style>

<UserControl.Resources>

and I set this as the base Button style using

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource BaseButtonStyle}"/>

so far so good. Next I want to have a second style with the only portion different being

<Border Background="{StaticResource Button.DefaultState.BorderNEWZ}"
//instead of
<Border Background="{StaticResource Button.DefaultState.Border2}"

so I’ve tried NEWSTYLETEST…

    <Style x:Key="NEWSTYLETEST" TargetType="{x:Type Button}" BasedOn="{StaticResource BaseButtonStyle}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ButtonBase}">
                    <Grid x:Name="Root" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid x:Name="FocusState" Opacity="0">
                            <Border CornerRadius="4" Style="{StaticResource FocusTemplate}"/>
                        </Grid>
                        <Grid x:Name="DefaultState">
                            <Border Background="{StaticResource Button.DefaultState.Border1}"
                                Padding="1" CornerRadius="3">
                                <Border Background="{StaticResource Button.DefaultState.BorderNEWZ}"
                                    Padding="1" CornerRadius="2">
                                </Border>
                            </Border>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

This does change the control part I need from Button.DefaultState.Border2 to Button.DefaultState.BorderNEWZ but it omits the remainder of the values contained in the rest of <Setter Property="Template"> in the base style.

I could just copy the whole of <Setter Property="Template"> each time and change the line I need but that seems overkill. Is there a way to target only Button.DefaultState.Border2 for change in each new style whilst keep everything else the same without repeating large chunks of the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:28:36+00:00Added an answer on June 11, 2026 at 4:28 am

    The BasedOn works on a per-property basis, so in this case you’ve told it to override the “Template” property. (all or nothing) Ultimately the answers you’ll be looking for are outlined here:

    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/abe21d46-8e32-4f33-bb8f-750bdc38cb14/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.