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

  • Home
  • SEARCH
  • 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 8502999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:38:20+00:00 2026-06-11T01:38:20+00:00

I have a UserControl with some buttons. I need to change the background colour

  • 0

I have a UserControl with some buttons. I need to change the background colour of the buttons but retain all other properties and colours such as mouseover events

I’ve used the following code which I hoped would define UniqueButton1 based on {StaticResource {x:Type Button}}" but change the background property to define my own colours

<UserControl x:Class="Project.Detail"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="30" d:DesignWidth="800" BorderBrush="#FF5380E7" BorderThickness="0,0,0,1" xmlns:my="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
    <UserControl.Resources>
        <Style  x:Key="UniqueButton1" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"  >
            <Setter Property="Background">
                <Setter.Value>
                <LinearGradientBrush EndPoint="0,1">
                    <GradientStop Color="#FFF896CE" Offset="0" />
                    <GradientStop Color="#FFF788C7" Offset="0.5" />
                    <GradientStop Color="#FFF570BB" Offset="0.5" />
                     <GradientStop Color="#FFF353AE" Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid Height="30" Width="800">
        <Button Height="30" HorizontalAlignment="Left" Margin="360,0,0,0" Name="button2" VerticalAlignment="Top" Width="50" Click="b_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10" FontStretch="SemiCondensed" />
        <Button Style="{StaticResource UniqueButton1}" Height="30" HorizontalAlignment="Left" Margin="423,0,0,0" Name="button1" VerticalAlignment="Top" Width="50" Click="b_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10" FontStretch="SemiCondensed" />
    </Grid>
</UserControl>

It kind of works, in that I get the background colours the way I need, but UniqueButton1 which I’ve defined in <UserControl.Resources> is not based on the other default button2 with no style changes applied. Eg, the background, colours, animation speeds etc are all different

Perhaps it’s because I’m also applying a theme?

My question is either
1. How do I define a resource that is based on a default button2 with a theme applied?
or
2. How do I get all of the properties of button2 with the theme applied so I can build my own style?

It’s been suggested I may need to build my own style, which is fine. But I need to match the behaviour of the default themed button except for the background property – if I can’t see how it’s made up it seems a bit of a catch22.

EDIT: To clarify things

enter image description here

enter image description here

These two images show 3 buttons, you can see the mousover for button3 is orange and blue for button2. What you can’t see is that the animation speed is also different. Essentially I want my button to look like button1 in the rest state and button3 on mouseover whilst retaining the button3 animation speed and other properties. Button2 is what I’m getting using basedon with no further properties changed.

Button3 is produced with no resources and XAML

<Button Height="30" HorizontalAlignment="Left" Margin="360,0,0,0" VerticalAlignment="Top" Width="50" Click="button_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10" FontStretch="SemiCondensed"/>

Button2 is produced using

<UserControl.Resources>
        <Style  x:Key="TEST1" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"  >
        </Style>
</UserControl.Resources>

<Button Style="{StaticResource TEST1}" Height="30" HorizontalAlignment="Left" Margin="360,0,0,0" VerticalAlignment="Top" Width="50" Click="button_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10" FontStretch="SemiCondensed"/>

Button1 is produced using

    <UserControl.Resources>
        <Style  x:Key="UniqueButton1" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"  >
            <Setter Property="Background">
                <Setter.Value>
                <LinearGradientBrush EndPoint="0,1">
                    <GradientStop Color="#FFF896CE" Offset="0" />
                    <GradientStop Color="#FFF788C7" Offset="0.5" />
                    <GradientStop Color="#FFF570BB" Offset="0.5" />
                     <GradientStop Color="#FFF353AE" Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

<Button Style="{StaticResource UniqueButton1}" Height="30" HorizontalAlignment="Left" Margin="360,0,0,0" VerticalAlignment="Top" Width="50" Click="button_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10" FontStretch="SemiCondensed" />

So obviously button 1 and 2 are not based on button3 which is what I want. I want to clone button3 properties and ONLY change the background to pink.

  • 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-11T01:38:22+00:00Added an answer on June 11, 2026 at 1:38 am

    Change your BaseButton from x:Type to a named one and then set it’s name on others BasedOn, that should do the trick.

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

Sidebar

Related Questions

I have made some progress with the DataList and UserControl this morning but I
I have a UserControl where I have some buttons and textboxes. I was wondering
I have a Custom UserControl . In that UserControl i have some buttons ,
I have a UserControl and it contains a Button . Now, in some Windows
Hi I have a usercontrol which includes some JavaScript, if I add the control
I have a WPF TabControl which displays UserControl s. Some UserControl s are larger
How to load/render a usercontrol using jquery? I have some menus on header of
I have a user control which uses objects as inner properties (some code is
I have a page with some controls, usercontrols etc. when I change a div
I am creating a series of UserControls that all have some similar business logic.

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.