2012-02-08 83 views
2

我无法计算如何将多边形的高度绑定到我的堆栈面板的高度。将多边形的高度绑定到StackPanel高度

如果我想添加一个矩形,我不得不做的是类似的东西:

     <Rectangle Width="75" > 
         <Rectangle.Fill> 
          <SolidColorBrush Color="Red" /> 
         </Rectangle.Fill> 
        </Rectangle> 

这人会不会刹车面板的高度。但对于多边形来说,我似乎不能将某些点留作空白,以便可以与父面板进行缩放。

enter image description here

感谢

回答

1

<Viewbox>包装你的多边形。

Viewbox自动将其内容缩放到其大小。它的确如此可以通过StretchStretchDirection属性进行调整。

+0

感谢您的答复罗斯,我怕我不知道如何来实现这一目标。我从MSDN中取出了Polygon样本,并使用StretchDirection =“UpOn​​ly”的ViewBox对其进行了扭曲。该多边形仍然会制动父堆叠面板的高度大小。 如果您可以提供您的实施示例代码,将非常感激。 谢谢。 – 2012-02-08 14:29:06

+0

好的,正如你所说,谢谢。 – 2012-02-08 14:37:34

1

此解决方案的工作太

enter image description here

<Grid> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="Auto" /> 
    </Grid.RowDefinitions> 
    <StackPanel Orientation="Horizontal"> 
    <Border BorderBrush="Black" BorderThickness="1,1,0,1"> 
     <StackPanel Orientation="Horizontal"> 
     <TextBlock Text="TextBlock1" Margin="2" /> 
     <TextBlock Text="TextBlock2" Margin="2" /> 
     <TextBlock Text="TextBlock3" Margin="2" /> 
     <TextBlock Text="TextBlock4" Margin="2" /> 
     <TextBlock Text="TextBlock5" Margin="2" /> 
     </StackPanel> 
    </Border> 
    <Path Fill="Yellow" Stroke="Black" StrokeThickness="1" 
    Width="50" Stretch="Fill"> 
     <Path.Data> 
     <PathGeometry> 
      <PathFigure IsClosed="True" StartPoint="1,0.5"> 
      <LineSegment Point="0,0" IsSmoothJoin="True" /> 
      <LineSegment Point="0,1" IsSmoothJoin="True" /> 
      </PathFigure> 
     </PathGeometry> 
     </Path.Data> 
    </Path> 
    </StackPanel> 
</Grid> 
+0

这正是我所期待的,非常感谢。但我会给Ross给V,因为他已经回答了,名声也较低。 – 2012-02-08 15:00:46

+0

@Esh没有问题:-) – punker76 2012-02-08 15:08:14