将多边形的高度绑定到StackPanel高度

时间:2012-02-08 13:59:02

标签: wpf visual-studio-2010 c#-4.0 expression-blend

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

如果我想添加一个矩形,我所要做的就是这样:

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

这个不会制动面板的高度。但是对于多边形,似乎我不能将一些点留空,以便与父面板一起缩放。

enter image description here

由于

2 个答案:

答案 0 :(得分:1)

<Viewbox>包裹多边形。

Viewbox会自动将其内容缩放到其大小。具体如何,可以使用StretchStretchDirection属性进行调整。

答案 1 :(得分: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>
相关问题