C# WPF Expander-水平对齐设置为右侧,但展开时会跳到左侧

C# WPF Expander-水平对齐设置为右侧,但展开时会跳到左侧,c#,wpf,C#,Wpf,我有一个右对齐的WPF扩展器。该位正确显示在屏幕上,但当您展开它时,扩展器和文本“显示/隐藏历史数据”会跳到屏幕左侧。关闭扩展器,使其返回正确(右)对齐状态 我尝试过各种方法,但无法找到发生这种情况的原因,更重要的是,无法找到如何保持扩展扩展器正确对齐的方法 <Grid Grid.Row="1" HorizontalAlignment="Stretch"> <Grid.RowDefinitions>

我有一个右对齐的WPF扩展器。该位正确显示在屏幕上,但当您展开它时,扩展器和文本“显示/隐藏历史数据”会跳到屏幕左侧。关闭扩展器,使其返回正确(右)对齐状态

我尝试过各种方法,但无法找到发生这种情况的原因,更重要的是,无法找到如何保持扩展扩展器正确对齐的方法

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

您可以控制
标题
,方法是明确地将其标记为
文本块
,然后将其更改为
水平对齐
属性:

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


我将您的代码放在示例应用程序中,没有发现扩展器有任何问题。您说展开时,展开文本会跳到屏幕的左侧。文本块文本会发生什么变化?它仍然可见吗?textblock仍然可见,因此扩展文本位于textblock文本的顶部-我现在想知道当项目被扩展时是否应用了textblock样式(不知道为什么会这样做)。当我尝试这种方法时,我得到一个错误,告诉我“属性头只能设置一次”?仅当我在Expander.Header之间添加Textblock时才会出现此选项brackets@Wobble:您应该删除
标题
属性的先前声明。