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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:02:34+00:00 2026-05-10T19:02:34+00:00

I have an Expander placed on a window with a blue background and I

  • 0

I have an Expander placed on a window with a blue background and I would like to make the button for the expander another color than the default (blue, which it is receiving from the window). When I modify the background property of the expander it changes the entire expander, header and all to the new color. However, I would like only the button itself to change. Could anyone point me to the right property that I am looking for? Thank you

  • 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. 2026-05-10T19:02:35+00:00Added an answer on May 10, 2026 at 7:02 pm

    You not only have to retemplate the Expander … you need to retemplate the ToggleButton within the Expander’s template … so that you can template bind the Background brush set on the Expander all the way down through the Expander’s visuals and into the ToggleButton’s visuals (using two TemplateBindings).

    One thing that is helpful (at least for me) when you are learning how to modify the visuals of the WPF controls is to use the SimpleStyles as these are much easier to copy and modify … than the full fledged, normal styles & templates.

    To do this, open up Blend and go into the Asset Library (the bottom most tool) … if you click on that you will see two sets of controls: System Controls and Simple Styles. Grab one of the controls (whichever one you want) from the Simple Styles and plunk it down on the design surface. Then, you can right click on it, Edit Control Parts (Template), and Edit a Copy. This will create a copy of the Simple Styles style and template … which you can then (more easily) modify to your hearts content.

    (I should note at this point that I would then modify that xaml (generated by Blend) in both Visual Studio and Blend … flipping back and forth as necessary … and taking advantage of the strengths of each: Blend for its WYSIWYG design surface … and Visual Studio for its code editing and IntelliSense support.)

    I have drafted up some quick xaml that does what you are asking and will include it below. You should be able to drop this xaml in Kaxaml or another loose xaml editor.

    Hope this helps.

    <Page     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     Width='640'     Height='480' >     <Page.Resources>         <LinearGradientBrush x:Key='NormalBrush' EndPoint='0,1' StartPoint='0,0'>             <GradientStop Color='#EEE' Offset='0.0'/>             <GradientStop Color='#CCC' Offset='1.0'/>         </LinearGradientBrush>         <LinearGradientBrush x:Key='NormalBorderBrush' EndPoint='0,1' StartPoint='0,0'>             <GradientStop Color='#CCC' Offset='0.0'/>             <GradientStop Color='#444' Offset='1.0'/>         </LinearGradientBrush>         <SolidColorBrush x:Key='GlyphBrush' Color='#444'/>         <LinearGradientBrush x:Key='MouseOverBrush' EndPoint='0,1' StartPoint='0,0'>             <GradientStop Color='#FFF' Offset='0.0'/>             <GradientStop Color='#AAA' Offset='1.0'/>         </LinearGradientBrush>         <LinearGradientBrush x:Key='PressedBrush' EndPoint='0,1' StartPoint='0,0'>             <GradientStop Color='#BBB' Offset='0.0'/>             <GradientStop Color='#EEE' Offset='0.1'/>             <GradientStop Color='#EEE' Offset='0.9'/>             <GradientStop Color='#FFF' Offset='1.0'/>         </LinearGradientBrush>          <ControlTemplate x:Key='newToggleButtonControlTemplate' TargetType='{x:Type ToggleButton}'>             <Grid Background='{TemplateBinding Background}'>                 <Rectangle                     x:Name='Rectangle'                     Margin='0,0,0,0'                     Fill='Transparent'                     Stroke='{DynamicResource NormalBorderBrush}'                 />                 <Path                     x:Name='Up_Arrow'                     HorizontalAlignment='Center'                     VerticalAlignment='Center'                     Fill='{DynamicResource GlyphBrush}'                     Data='M 0 0 L 4 4 L 8 0 Z'                 />                 <Path                     x:Name='Down_Arrow'                     Visibility='Collapsed'                     HorizontalAlignment='Center'                     VerticalAlignment='Center'                     Fill='{DynamicResource GlyphBrush}'                     Data='M 0 4 L 4 0 L 8 4 Z'                 />             </Grid>             <ControlTemplate.Triggers>                 <Trigger Property='IsMouseOver' Value='true'>                     <Setter Property='Fill' Value='{DynamicResource MouseOverBrush}' TargetName='Rectangle'/>                 </Trigger>                 <Trigger Property='IsPressed' Value='true'>                     <Setter Property='Fill' Value='{DynamicResource PressedBrush}' TargetName='Rectangle'/>                 </Trigger>                 <Trigger Property='IsChecked' Value='true'>                     <Setter Property='Visibility' Value='Visible' TargetName='Down_Arrow'/>                     <Setter Property='Visibility' Value='Collapsed' TargetName='Up_Arrow'/>                 </Trigger>             </ControlTemplate.Triggers>         </ControlTemplate>         <Style x:Key='newExpanderStyle' TargetType='{x:Type Expander}'>             <Setter Property='Template'>                 <Setter.Value>                     <ControlTemplate TargetType='{x:Type Expander}'>                         <Grid>                             <Grid.RowDefinitions>                                 <RowDefinition Height='Auto'/>                                 <RowDefinition Height='*' x:Name='ContentRow'/>                             </Grid.RowDefinitions>                             <Border                                 x:Name='Border'                                 Grid.Row='0'                                 BorderThickness='{TemplateBinding BorderThickness}'                                 CornerRadius='2,2,0,0'                             >                                 <Grid>                                     <Grid.ColumnDefinitions>                                         <ColumnDefinition Width='20'/>                                         <ColumnDefinition Width='*'/>                                     </Grid.ColumnDefinitions>                                     <ToggleButton                                         Template='{DynamicResource newToggleButtonControlTemplate}'                                         Background='{TemplateBinding Background}'                                         IsChecked='{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}'                                         OverridesDefaultStyle='True'                                     />                                     <ContentPresenter Grid.Column='1' Margin='4' RecognizesAccessKey='True' ContentSource='Header'/>                                 </Grid>                             </Border>                             <Border                                 x:Name='ExpandSite'                                 Grid.Row='1'                                 Visibility='Collapsed'                                 BorderThickness='1,0,1,1'                                 CornerRadius='0,0,2,2'                             >                                 <ContentPresenter                                     HorizontalAlignment='{TemplateBinding HorizontalContentAlignment}'                                     VerticalAlignment='{TemplateBinding VerticalContentAlignment}'                                     Margin='{TemplateBinding Padding}'                                     Focusable='false'                                 />                             </Border>                         </Grid>                         <ControlTemplate.Triggers>                             <Trigger Property='IsExpanded' Value='True'>                                 <Setter Property='Visibility' Value='Visible' TargetName='ExpandSite'/>                             </Trigger>                         </ControlTemplate.Triggers>                     </ControlTemplate>                 </Setter.Value>             </Setter>         </Style>     </Page.Resources>      <Page.Background>         <LinearGradientBrush EndPoint='0.997,0.996' StartPoint='0.002,0.058'>             <GradientStop Color='#FF63A6DE' Offset='0'/>             <GradientStop Color='#FFC2DEF5' Offset='1'/>         </LinearGradientBrush>     </Page.Background>      <Grid x:Name='LayoutRoot'>         <Expander             Style='{DynamicResource newExpanderStyle}'             Header='Expander'             HorizontalAlignment='Left'             VerticalAlignment='Top'             Background='{DynamicResource NormalBrush}'         >             <Grid>                 <Button Content='Hello World'/>             </Grid>         </Expander>     </Grid> </Page> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have something like a resizable Expander. My basic idea was
I have a WPF window with expandable panel (via Expander ). The panel is
I have a snippet to create a 'Like' button for our news site: <iframe
I have button. I have expander in button and label above expander in the
I have 4 expander controls. When one expander is expanded, how can I make
In WPF I'd like to have an expander that shows a stack of labels
I have a silverlight expander control which wraps a grid. In the grid, I
I have a stack panel inside of an expander panel that I programaticaly adds
I have a custom template for an expander that is close to the code
Have just started using Visual Studio Professional's built-in unit testing features, which as I

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.