Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expander header text alignment

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:

enter image description here

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?

like image 386
Kirsty White Avatar asked Apr 15 '12 17:04

Kirsty White


People also ask

How do I align the content of an expander control?

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.

What is text alignment in AutoCAD?

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 ...

What are the default text alignment settings?

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):

How do I create an expander in the XAML Controls Gallery?

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.


3 Answers

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>
like image 136
honzakuzel1989 Avatar answered Oct 01 '22 21:10

honzakuzel1989


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.

like image 45
H.B. Avatar answered Oct 01 '22 20:10

H.B.


An example here supporting above suggestions.

like image 27
Neyamat Ullah Avatar answered Oct 01 '22 21:10

Neyamat Ullah