将 Polygon 的高度绑定到 StackPanel 的高度

发布于 2025-01-03 20:01:22 字数 474 浏览 3 评论 0原文

我不知道如何将多边形的高度绑定到堆栈面板的高度。

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

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

这个矩形不会限制面板的高度。但对于多边形,我似乎无法将某些点保留为空白,以便与父面板一起缩放。

在此处输入图像描述

谢谢

I can't figure how to bind the height of a polygon to the height of my stack panel.

If I wanted to add a rectangle, all I had to do is something like that:

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

This one won't brake the height of the panel. but with the polygon it seems like I can't leave some of the points as blank so that will scale with the parent panel.

enter image description here

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不羁少年 2025-01-10 20:01:22

包裹多边形。

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

Wrap your polygon with a <Viewbox>.

The Viewbox automatically scales its content to its size. Exactly how it does so can be tweaked with the Stretch and StretchDirection properties.

有深☉意 2025-01-10 20:01:22

这个解决方案也有效

在此处输入图像描述

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

this solution works too

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文