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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:28:54+00:00 2026-05-15T03:28:54+00:00

I am using the Expander control and have styled the header as shown in

  • 0

I am using the Expander control and have styled the header as shown in the picture below:

http://www.hughgrice.com/Expander.jpg

The problem I have is that I want the expander button to be contained within the header so that the line for the end of the header template aligns with the Expander content i.e. I ultimatly want to end up with something similar to the image below:

http://www.hughgrice.com/Expander.gif

Thanks in advance.

  • 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-15T03:28:54+00:00Added an answer on May 15, 2026 at 3:28 am

    I see that you want to actually move the expander button into your HeaderTemplate, not just restyle it. This is easily done with FindAncestor:

    First add a ToggleButton and bind its IsChecked property using FindAncestor, along these lines:

    <DataTemplate x:Key="MyHeaderTemplate">
      <Border ...>
        <DockPanel>
          <!-- Expander button -->
          <ToggleButton
             IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor,Header,1}}"
             Content=... />
    
          <!-- Other content here -->
          ...
        </DockPanel>
      </Border>
    </DataTemplate>           
    

    This adds an expand button inside the header template but does not hide the original button provided by the Expander. To do this I recommend you replace the Expander’s ControlTemplate.

    Here is a complete copy of Expander’s ControlTemplate with the ToggleButton replaced with a simple ContentPresenter:

    <ControlTemplate x:Key="ExpanderWithoutButton" TargetType="{x:Type Expander}">
      <Border BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}"
              Background="{TemplateBinding Background}"
              CornerRadius="3"
              SnapsToDevicePixels="true">
        <DockPanel>
          <ContentPresenter
            Content="{TemplateBinding Header}"
            ContentTemplate="{TemplateBinding HeaderTemplate}"
            ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
            DockPanel.Dock="Top"
            Margin="1"
            Focusable="false" />
          <ContentPresenter
            x:Name="ExpandSite"
            Visibility="Collapsed"
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
            Margin="{TemplateBinding Padding}"
            Focusable="false" />
        </DockPanel>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="IsExpanded" Value="true">
          <Setter Property="Visibility" Value="Visible" TargetName="ExpandSite"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="false">
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
    

    It might be used as follows:

    <Expander Template="{StaticResource ExpanderWithoutButton}">
    
      <Expander.HeaderTemplate>
        <DataTemplate ...>
          <Border ...>
            <DockPanel>
              <ToggleButton ...
                IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor,Header,1}}" />
              ... other header template content here ...
    

    A simpler alternative would be to just set a negative margin in yourHeaderTemplate to cover the expander button. Instead of the ControlTemplate shown above, your DataTemplat would just contain something like this:

    <DataTemplate ...>
      <Border Margin="-20 0 0 0" ... />
    

    Adjust the negative margin to get the look you want. This solution is simpler but inferior in that if you switch to a different system theme the required margin may change and your expander may no longer look good.

    • 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.