6

Hi I was wondering is it possible to align the toggle button on a WPF expander control to the far right side?

Petezah
  • 1,465
  • 4
  • 26
  • 30
  • Why do u have to do such lengthy process when there is a simple process here in the link provided below. http://stackoverflow.com/questions/9288342/how-to-put-wpf-expander-toggle-button-on-right – Nikhil Agrawal Feb 15 '12 at 07:18

1 Answers1

15

With WPF all things are possible. ;) Unfortunately not all things are simple. Your best bet here is to re-template the expander. Start out by copying the default Expander template, found here.

Next, find the Grid that contains 2 columns, one containing a ToggleButton and the other containing a ContentPresenter. Swap the columns so the toggle is in column 1. Then change the column definition sizes so the first column is star-sized, and the second is size 20. When finished, you should have a chunk in the template that looks like this:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="20" />
  </Grid.ColumnDefinitions>
    <ToggleButton Grid.Column="1"
      IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,
      RelativeSource={RelativeSource TemplatedParent}}"
      OverridesDefaultStyle="True" 
      Template="{StaticResource ExpanderToggleButton}" 
      Background="{StaticResource NormalBrush}" />
    <ContentPresenter Margin="4" 
      ContentSource="Header" 
      RecognizesAccessKey="True" />
</Grid>

Continue modifying the template until you get the look and feel that you need.

EDIT: The template provided on MSDN is a bare-bones version of the "real" expander template. If you want the stylized expander template, use Expression Blend and copy the existing control template off an Expander.

Charlie
  • 15,069
  • 3
  • 64
  • 70