将可调整大小的Expander从右向左扩展

时间:2012-01-13 09:26:03

标签: wpf xaml grid expander gridsplitter

我想从下面的问题中找到扩展器(参见接受的答案),这对我来说是一个完美的解决方案。我只想把它放在右侧。

Combine expander and grid (resizable expander)

为了让它从右向左扩展,我改变了类似行为的设置。 (我强调了能够更好地了解正在发生的事情的因素):

<Expander Grid.Column="1" Header="Test" ExpandDirection="Left" 
        BorderThickness="10" BorderBrush="Black" HorizontalAlignment="Right" >
  <Expander.Content>
    <Grid >
       <Grid.ColumnDefinitions>
         <ColumnDefinition Width="Auto"/>
         <ColumnDefinition Width="Auto" />
       </Grid.ColumnDefinitions>
       <GridSplitter Grid.Column="0" Width="10" Background="Green" 
                  ResizeDirection="Columns" ResizeBehavior="CurrentAndNext" />
       <TextBox Grid.Column="1" Text="Lorem ipsum dolor sit" 
             BorderThickness="10" BorderBrush="Red"/>
    </Grid>
  </Expander.Content>
</Expander>

当我将分离器向右移动时,它会调整分离器左侧区域的大小。我尝试了很多其他组合,但它几乎导致了相同的不良行为。分割器左侧的区域有时会出现奇怪的爆炸,但TextBox保持不变。

1 个答案:

答案 0 :(得分:9)

试试这样:

<Expander Grid.Column="1" Header="Test" ExpandDirection="Left"
    BorderThickness="10" BorderBrush="Black" HorizontalAlignment="Right">
  <Expander.Content>
    <Grid>
       <Grid.ColumnDefinitions>
         <ColumnDefinition Width="*" MinWidth="10" />
         <ColumnDefinition Width="Auto" />
       </Grid.ColumnDefinitions>
       <GridSplitter Grid.Column="0" Width="10" Background="Green"
                  ResizeDirection="Columns" ResizeBehavior="CurrentAndNext" />
       <TextBox Grid.Column="1" Text="Lorem ipsum dolor sit"
             BorderThickness="10" BorderBrush="Red"/>
    </Grid>
  </Expander.Content>
</Expander>