7

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> 
Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104

1 Answers1

15

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>     
Kols
  • 3,641
  • 2
  • 34
  • 42
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
  • +1 for a partial solution + code fix. But this will keep the elements inside the Expander vertically stacked on TOP of each other. I am trying to set the elements BESIDE each other then slide right/left. – Khalil Khalaf Mar 11 '16 at 20:13
  • @FirstStep...You could use `Orientation="Horizontal"` of the inner `StackPanel`. Ckeck my updated answer. – Salah Akbari Mar 11 '16 at 20:14