[英]WPF Expander - Horizontal Alignment set to Right, but jumps to left on when expanded
I've got a WPF Expander that is right aligned. 我有一个正确对齐的WPF扩展器。 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>
YOu can take control of the Header
by explictly marking it as a TextBlock
and then change itś HorizontalAlignment
property: 您可以通过将
Header
明确标记为TextBlock
然后更改它的HorizontalAlignment
属性来控制Header
:
<Expander.Header>
<TextBlock
Width="200"
HorizontalAlignment="Right"
Text="Show information.."></TextBlock>
</Expander.Header>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.