Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put Expander ToggleButton on right

Tags:

c#

wpf

expander

By default the expander has a left aligned toggle button but in my WPF app i want toggle button on the right side of the header without the help of Expression Blend. just plain XAML and/or C#. My expander contains a vertically oriented stackpanel which has labels as its child.

I went for its part but here it says "The Expander control does not have any named parts".

I found an example here. But it overrides the default Expander Style.

I think the attached image should convey what i want. How to do. Any link would be helpful.

enter image description here

like image 771
Nikhil Agrawal Avatar asked Feb 15 '12 05:02

Nikhil Agrawal


2 Answers

Use this:

<Expander Header="Expander1" FlowDirection="RightToLeft">
    <TextBlock FlowDirection="LeftToRight">
    </TextBlock>
</Expander>

Add your content in the TextBlock, if you don't want to the whole content to be right to left.

like image 88
Mohammad Dehghan Avatar answered Oct 23 '22 15:10

Mohammad Dehghan


There is a trick that can help

<Expander Header="My Expander" 
          FlowDirection="RightToLeft">
    <Expander.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=Header}"
                       Width="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=ActualWidth}" 
                       Margin="-30,0,0,0"
                       FlowDirection="LeftToRight">
            </TextBlock>
        </DataTemplate>
    </Expander.HeaderTemplate>
</Expander>
like image 29
Nitesh Avatar answered Oct 23 '22 15:10

Nitesh