How to set Expander Direction to slide horizontally instead of vertically?
Asked Answered
R

1

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> 
Roscoeroscommon answered 11/3, 2016 at 19:52 Comment(0)
D
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>     
Doge answered 11/3, 2016 at 19:56 Comment(2)
+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.Roscoeroscommon
@FirstStep...You could use Orientation="Horizontal" of the inner StackPanel. Ckeck my updated answer.Doge

© 2022 - 2024 — McMap. All rights reserved.