Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expander button on the right side: how to do it?

Expander in right side how ?

i want to position the Expander button on the right side of the label. How to do this?

like image 783
Sender Avatar asked Jan 07 '12 13:01

Sender


3 Answers

You can also set the FlowDirection to RightToLeft, but that may cause other problems. For example it also changes the flow direction for the content of the expander so you may need to set it back.

<Expander FlowDirection="RightToLeft">
     <StackPanel FlowDirection="LeftToRight">
     </StackPanel>
</Expander>
like image 116
Ray Avatar answered Nov 19 '22 21:11

Ray


You must restyle the control's template. Here's an example: http://patconroy.wordpress.com/2008/12/18/restyling-the-wpf-expander-control/

like image 32
myermian Avatar answered Nov 19 '22 19:11

myermian


Another way to approach this is to position the expander where you like, without any header or content in the expander itself. Then bind the visibility of your content-control to the expanders IsExpanded property, using a BooleanToVisibilityConverter.

<StackPanel>
    <StackPanel.Resources>
        <BooleanToVisibilityConverter x:Key="boolToVisibility" />
    </StackPanel.Resources>
    <DockPanel>
        <Expander DockPanel.Dock="Right" x:Name="rightAlignedExpander" />
        <TextBlock Text="Expanders header" VerticalAlignment="Center" />
    </DockPanel>
    <Grid Visibility="{Binding IsExpanded, ElementName=rightAlignedExpander, Converter={StaticResource boolToVisibility}}">
    <TextBlock Text="Expanders content"/>
    </Grid>
</StackPanel>

The downside is that it will not expand when the header is clicked, but that could easily be implemented if necessary.
Personally I think this is more simple and straightforward instead of completely restyling the control's template. It also have the added benefit that it will keep any styles already applied to the expander, for example when using 3rd party themes like DevExpress or Telerik.

like image 4
Kenneth_hj Avatar answered Nov 19 '22 21:11

Kenneth_hj