So I changed the orientation of the expander to align vertically rather than horizontally but in the closed state the expander header text is aligning horizontally. Please tell me there is a way to easily fix this without expression blend etc.
<Expander Header="My Header">
I was hoping for something like AlignHeaderText
vertically but I see no options for it? Does anyone have a different way they could "show" me?
So taking from the mentoring H.B provided I came up with this:
<StackPanel Orientation="Horizontal" Margin="0,0,342,0" Width="318">
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Expander.Expanded" SourceName="expander1">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation From="0" To="1.2" Duration="0:0:0.45" Storyboard.TargetName="content" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleX)"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
<Expander ExpandDirection="Right" Name="expander1" OpacityMask="#6C806969" Background="#FF807171">
<Expander.LayoutTransform>
<RotateTransform Angle="90"></RotateTransform>
</Expander.LayoutTransform>
<Expander.Header>
<TextBlock
Text="HEADER"
Width="{Binding
RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type Expander}},
Path=ActualWidth}"
/>
</Expander.Header>
<Grid x:Name="content" Background="#FF807171" Width="178">
<Grid.LayoutTransform>
<ScaleTransform ScaleX="0" ScaleY="1"/>
</Grid.LayoutTransform>
</Grid>
</Expander>
Unfortunately it does this to the expander:
It places the text at the top and the button in the middle, I was hoping for the button at the top and the text after the button?
If I change Path=ActualWidth
to Height
the button moves up but the header text is still left of the button and not below it?
You can align content by setting the HorizontalContentAlignment and VerticalContentAlignment properties on the Expander control. When you set these properties, the alignment applies only to the expanded content, not the header. By default, the Header and Content areas automatically size to fit their contents.
Text Alignment. The text-align property is used to set the horizontal alignment of a text. A text can be left or right aligned, centered, or justified. The following example shows center aligned, and left and right aligned text (left alignment is default if text direction is left-to-right, and right alignment is default if text direction is ...
The following example shows center aligned, and left and right aligned text (left alignment is default if text direction is left-to-right, and right alignment is default if text direction is right-to-left):
If you have the XAML Controls Gallery app installed, click here to open the app and see Expander in action. This example shows how to create a simple Expander with the default styling. The Header property defines the element that is always visible. The Content property defines the element that can be collapsed and expanded.
My solution (without another properties) - based on H.B. and Sheikh Neyamat answers:
<Expander ExpandDirection="Right">
<Expander.Header>
<TextBlock Text="Header">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"/>
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
// Content - listbox in my case
</Expander>
Assign a TextBlock
as Header
via element syntax and apply a RotateTransform
as the TextBlock
's LayoutTransform
to get the rotation. If you want vertical text that can be done differently.
An example here supporting above suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With