Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Expander Direction to slide horizontally instead of vertically?

I know that the System.Windows.Controls.Expander is another "headered" content control in WPF just similar to a System.Windows.Controls.GroupBox. One advantage is that Expanders have the ability to hide its content by collapsing, and showing content by expanding.

My question is, what if I want my Expander to slide horizontally from left to right or right to left instead of vertically? and let's say I have the below Expander:

<StackPanel x:Name="RightPanel">
    <Expander x:Name="ExportExpander">
        <StackPanel>
            <TextBlock Name="x" Text="Element One"/>
            <Button Name="y" Content="Element Two"/>
        </StackPanel>
    </Expander>
</StackPanel> 
like image 937
Khalil Khalaf Avatar asked Mar 11 '16 19:03

Khalil Khalaf


1 Answers

You could use ExpandDirection property of the Expander like this:

<Expander x:Name="ExportExpander" ExpandDirection="Right">

Also the correct code is like below:

<StackPanel x:Name="RightPanel">
    <Expander x:Name="ExportExpander" ExpandDirection="Right">
        <StackPanel Orientation="Horizontal">
            <TextBlock Name="x" Text="Element One"/> <!--Textblock has Text property-->
            <Button Name="y" Content="Element Two"/>
        </StackPanel>
    </Expander>
</StackPanel>     
like image 101
Salah Akbari Avatar answered Oct 09 '22 02:10

Salah Akbari