2012-05-20 79 views
2

我需要一个面板,其中3个项目水平排列,一个左对齐,一个右对齐,最后一个居中于剩余空间。我可以得到这个:面板大小调整行为

<DockPanel LastChildFill="True"> 
    <TextBlock DockPanel.Dock="Left" Text="TextLeft" FontSize="40" Foreground="DarkOrange"/> 
    <TextBlock DockPanel.Dock="Right" Text="TextRight" FontSize="40" Foreground="DarkOrange"/> 
    <TextBlock Text="TextMiddle" FontSize="40" HorizontalAlignment="Center"/> 
</DockPanel> 

enter image description here

但我想,当宽度大于项目宽度的总和,这是“TextRight”那个被吃进NOT“TextMiddle”较小如下图所示:

enter image description here

注意我用尽上TextMiddle加入MinWidth - 但这变化的行为 - 因为TextMiddle是LastCh的最后一个孩子ildFill =“True”DockPanel。

下面的XAML让我在调整大小的正确behavor(TextRight被吃进时,在有限的空间)但“TextMiddle”当有足够的宽度没有可用空间中心

<DockPanel LastChildFill="False" > 
    <TextBlock DockPanel.Dock="Left" Text="TextLeft" FontSize="40" Foreground="DarkOrange"/> 
    <TextBlock DockPanel.Dock="Left" Text="TextMiddle" FontSize="40" HorizontalAlignment="Center" /> 
    <TextBlock DockPanel.Dock="Right" Text="TextRight" FontSize="40" Foreground="DarkOrange"/> 
</DockPanel> 

enter image description here enter image description here

我敢肯定有一个简单的解决方案,这一点 - 也许通过在项目中的一个使用subpannel - 但我只是不能让我的头究竟是如何左右。任何帮助非常感谢。

回答

1

也许是这样吗?

<Grid> 
    <Grid.RowDefinitions> 
    <RowDefinition /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="2*" MinWidth="350"/> 
    <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <UniformGrid HorizontalAlignment="Stretch" Rows="1"> 
     <TextBlock Name="TextLeft" Text="TextLeft" FontSize="40" Foreground="DarkOrange"/> 
     <TextBlock Name="TextMiddle" Text="TextMiddle" FontSize="40" HorizontalAlignment="Center" /> 
    </UniformGrid> 
    <TextBlock Grid.Column="1" HorizontalAlignment="Right" Text="TextRight" FontSize="40" Foreground="DarkOrange"/> 
</Grid> 
+0

这不是那么完美 - 它给出了与我的第二个xaml块相同的行为(即调整行为正确但MiddeText未居中于可用空间)。但我认为你的方法是好的 - 应该能够把这个解决方案变成一个解决方案......不知何故。 – Ricibob

+0

现在呢? – codekaizen

+1

坚持不懈!随着一些MinWidth摆脱工作。非常感谢你为此付出的努力 - 虽然比我第一次更困难(我想这就是WPF)。 :-) – Ricibob