Khalil Khalaf
Khalil Khalaf

Reputation: 9397

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> 

Upvotes: 7

Views: 7566

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39966

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>     

Upvotes: 15

Related Questions