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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:58:27+00:00 2026-05-15T11:58:27+00:00

I’m currently trying to create a ControlTemplate for the Button class in WPF, replacing

  • 0

I’m currently trying to create a ControlTemplate for the Button class in WPF, replacing the usual visual tree with something that makes the button look similar to the little (X) close icon on Google Chrome’s tabs. I decided to use a Path object in XAML to achieve the effect. Using a property trigger, the control responds to a change in the IsMouseOver property by setting the icon’s red background.

Here’s the XAML from a test app:

<Window x:Class="Widgets.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">

  <Window.Resources>
    <Style x:Key="borderStyle" TargetType="Border">
      <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Setter Property="Background">
            <Setter.Value>
              <SolidColorBrush Color="#CC0000"/>
            </Setter.Value>
          </Setter>
        </Trigger>
      </Style.Triggers>
    </Style>

    <ControlTemplate x:Key="closeButtonTemplate" TargetType="Button">
      <Border Width="12" Height="12" CornerRadius="6"
              BorderBrush="#AAAAAA" Background="Transparent"
              Style="{StaticResource borderStyle}"
              ToolTip="Close">
        <Viewbox Margin="2.75">
          <Path Data="M 0,0 L 10,10 M 0,10 L 10,0" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType=Border, AncestorLevel=1}}" StrokeThickness="1.8"/>
        </Viewbox>
      </Border>
    </ControlTemplate>
  </Window.Resources>

  <Grid Background="White">
    <Button Template="{StaticResource closeButtonTemplate}"/>
  </Grid>

</Window>

Note that the circular background is always there – it’s just transparent when the mouse isn’t over it.

The problem with this is that the trigger just isn’t working. Nothing changes in the button’s appearance. However, if I remove the Background="Transparent" value from the Border object in the ControlTemplate, the trigger does work (albeit only when over the ‘X’).

I really can’t explain this. Setters for any other properties placed in the borderStyle resource work fine, but the Background setter fails as soon as the default background is specified in the ControlTemplate.

Any ideas why it’s happening and how I can fix it? I know I could easily replace this code with, for example, a .PNG-based image, but I want to understand why the current implementation isn’t working.

Thanks! 🙂

  • 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-15T11:58:28+00:00Added an answer on May 15, 2026 at 11:58 am

    Try moving the explict “Background” assignment from inside the Border declaration to the Style itself:

    <Style x:Key="borderStyle" TargetType="Border">
        <Setter Property="Background" Value="Transparent" />
    
        <Style.Triggers> 
            <Trigger Property="IsMouseOver" Value="True"> 
                <Setter Property="Background"> 
                <Setter.Value> 
                    <SolidColorBrush Color="#CC0000"/> 
                </Setter.Value> 
            </Setter> 
        </Trigger> 
    </Style.Triggers> 
    
    ...
    
    <Border Width="12" Height="12" CornerRadius="6" 
            BorderBrush="#AAAAAA" 
            Style="{StaticResource borderStyle}" 
            ToolTip="Close"> 
    

    Styles can’t override a property that has been explicitly set. You need to set the value in the style.

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

Sidebar

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.