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 6365983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:21:49+00:00 2026-05-25T00:21:49+00:00

I am trying to design a button-template, that swaps its colors, when pressed. Unluckily

  • 0

I am trying to design a button-template, that swaps its colors, when pressed.

Unluckily I cant get it to work.

I am using the BorderBrush as a temporary variable. Most likely there are more sophisticated solutions possible.

Here is my code.

    <Style TargetType="{x:Type Button}">
        <Style.Setters>
            <Setter Property="Foreground"
                    Value="{StaticResource RahmenFarbe}" />
            <Setter Property="Background"
                    Value="{StaticResource HintergrundFarbe}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid Width="{TemplateBinding Width}"
                              Height="{TemplateBinding Height}"
                              ClipToBounds="True">
                            <Border BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Foreground}"
                                    x:Name="ButtonBorder"
                                    CornerRadius="25"
                                    BorderThickness="4"
                                    Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Background}"
                                    RenderTransformOrigin="0.5,0.5">
                                <TextBlock  x:Name="ButtonTextBlock"
                                            Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}, Path=Foreground}"
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center">
                                <ContentPresenter x:Name="myContentPresenter"
                                                  Content="{TemplateBinding Content}" />
                                </TextBlock>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed"
                                     Value="True">
                                <Setter Property="BorderBrush"
                                        Value="{Binding Mode=OneTime, Path=Foreground}" />
                                <Setter Property="Foreground"
                                        Value="{Binding Mode=OneTime, Path=Background}" />
                                <Setter Property="Background"
                                        Value="{Binding Mode=OneTime, Path=BorderBrush}" />
                            </Trigger>
                        </ControlTemplate.Triggers >

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>

Any help would be appreciated.

Regards Sebastian

  • 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-05-25T00:21:50+00:00Added an answer on May 25, 2026 at 12:21 am

    Update

    Finally understood what you really wanted to do. Here is how you get it done. Bind to the TemplatedParent‘s Background and Foreground and set TargetName in the setters. This way, the source for the colors will always stay the same and you can easily swap them

    <ControlTemplate.Triggers>
        <Trigger Property="IsPressed" Value="True">
            <Setter TargetName="ButtonBorder"
                    Property="Background"
                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}" />
            <Setter TargetName="ButtonTextBlock"
                    Property="Foreground"
                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
        </Trigger>
    </ControlTemplate.Triggers>
    

    Optionally, you can also change the Bindings in your Template from

    Background="{Binding Path=Background,
                         RelativeSource={RelativeSource FindAncestor,
                                                        AncestorType=Button,
                                                        AncestorLevel=1}}"
    

    To just

    Background="{TemplateBinding Background}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to design a menu that is triggered by clicking a button.
I'm trying to design a JButton (an Ok button) that to look good has
I'm trying to design a homepage for an MVC site that has two different
i m trying to design a mmo game using python... I have evaluated stackless
I am trying to design an object model (for C#), and can't work out
I'm trying to design an Android layout that would look like the following: Entity1
So I'm trying to work out how to design my wire-frame. It is essentially
I have been trying to find a good-looking design using Aero in Delphi 2010.
I'm trying to design a button with orange background and rounded borders but the
I am trying to design an ASP.net based mobile web application that should run

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.