Search code examples
wpfheaderexpander

Vertical Epander Would Like Vertical Header


This Expander is vertical. The Header displays as Hightlight

I want

H
i
g
h
l
i
g
h
t

How do it get that?

 <Expander Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right"
    VerticalAlignment="Stretch" Header="Highlight" 
    ExpandDirection="Left" IsExpanded="False" Width="Auto">

And the solution is

   <Expander Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Stretch" ExpandDirection="Left" IsExpanded="False" Width="Auto">
        <Expander.Header>
              <TextBlock><ItemsControl ItemsSource="Highlight" /></TextBlock>  
        </Expander.Header>

HB if you want to post it as as an answer I will accept it.


Solution

  • Either use property element syntax, as HB notes, or if you'd like to apply the style generically, define a DataTemplate style for your expander, like so :

    <Grid.Resources>
      <DataTemplate x:Key="verticalHeader">
        <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=Header}" />
      </DataTemplate>
    
      <Style TargetType="{x:Type Expander}">
        <Setter Property="HeaderTemplate" Value="{StaticResource verticalHeader}"/>
      </Style>
    </Grid.Resources>