0
votes

I've got a WPF Expander that is right aligned. That bit shows correctly on the screen, but when you expand it the expander and the text "show/hide historic data" jumps to the left of the screen. Close the expander and it returns to the correct (right) alignment.

I've tried various approaches but am unable to find why this is happening or more importantly how to keep an expanded expander right aligned

  <Grid Grid.Row="1"                    
    HorizontalAlignment="Stretch">
     <Grid.RowDefinitions>
      <RowDefinition Height="auto"/>
      <RowDefinition Height="auto"/>                               
     </Grid.RowDefinitions>
     <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*" />
     </Grid.ColumnDefinitions>

      <StackPanel Grid.Row="0"  >
            <TextBlock Style="{StaticResource SubHeader}" Text="Historic Data Sets" />                                               
           <Rectangle Style="{StaticResource HeaderLine}"/>
      </StackPanel>

       <Expander Header="show/hide historic data"
                 Grid.Column="1"
                 IsEnabled="True" 
                 VerticalAlignment="Center" 
                 HorizontalAlignment="Right" 
                 ExpandDirection="Down">       

   <!-- some other stuff in the second row such as grid... -->
</Expander>
1
I put your code in a sample app and couldn't see any issues with the expander. You say the expander text jumps to the left of the screen when expanded. What happens to the text block text? is it still visible?Rahul Vijay Dawda
The textblock is still visible so the expander text sits on top of the textblock text - I'm now wondering if textblock style is being applied when the item is expanded (no idea why it would do this though)Wobble

1 Answers

0
votes

YOu can take control of the Header by explictly marking it as a TextBlock and then change itś HorizontalAlignment property:

<Expander.Header>
    <TextBlock 
        Width="200"
        HorizontalAlignment="Right"
        Text="Show information.."></TextBlock>
</Expander.Header>