gpt4 book ai didi

WPF 路径 : How to Draw this in XAML?

转载 作者:行者123 更新时间:2023-12-04 14:42:39 24 4
gpt4 key购买 nike

我想创建一个带有非矩形标题的自定义 GroupBox,如下图所示:

enter image description here

如你所见,header的内容必须是参数化的,所以图片、标题和背景都可以在xaml中输入。

提前致谢。


感谢您的回答。

实际上我想在自定义组框中使用此设计,所以在您的回答中,如果我不设置网格的宽度和高度(宽度=150 高度=30),形状组件就会分开,所以我想要形状处于独特的主体中,因此很容易应用背景颜色。顺便说一句,你能像下图那样圆角吗?

enter image description here

最佳答案

试试这个

  <Grid Width="150" Height="30">
<Border CornerRadius="15,0,0,0" Background="SkyBlue" Height="30" Width="100" HorizontalAlignment="Left"></Border>
<Path Data="M 100,0 L 150,40 L 100 40 Z" Fill="SkyBlue"></Path>
<TextBlock Text="&#xE161;" FontFamily="Segoe Ui Symbol" Margin="10,0,0,0" FontSize="20" ></TextBlock>
<TextBlock Text="Configuration" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>

解释

我使用了 border,因为 border 有 cornerRadius 属性。

<Border CornerRadius="15,0,0,0" Background="SkyBlue" Height="30" Width="100" HorizontalAlignment="Left">

enter image description here

路径数据是

  <Path Data="M 100,0 L 150,40 L 100 40 Z" Fill="SkyBlue"></Path>

enter image description here

使用坐标系,我使用起始点 M 100,0 作为边界为 100,我使用 40 作为数据中的路径高度,使用 150 作为网格总网格宽度。和 Z 用于关闭路径数据。 enter image description here

最终输出

enter image description here

更新您可以根据需要使用 viewbox 缩放此图,我还添加了圆角曲线

第一种方法

<Viewbox>
<Grid Width="150" Height="30">
<Border CornerRadius="20,0,0,0" Background="SkyBlue" Height="30" Width="103" HorizontalAlignment="Left"></Border>
<Path Name="myPathShape" Fill="SkyBlue" >
<Path.Data>
<EllipseGeometry x:Name="MyEllipseGeometry" Center="90,45" RadiusX="40" RadiusY="50" />
</Path.Data>
</Path>
<TextBlock Text="&#xE161;" FontFamily="Segoe Ui Symbol" Margin="10,0,0,0" FontSize="20" ></TextBlock>
<TextBlock Text="Configuration" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>
</Viewbox>

第二种方法

    <Viewbox>
<Grid Width="150" Height="30">
<Border CornerRadius="15,0,0,0" Background="SkyBlue" Height="30" Width="103" HorizontalAlignment="Left"></Border>
<Path Data="M98.625,0.25 C104.076,-1.14832 109.448,2.02746 114.75,9.25 L130.125,29.8739 L102.25,29.9989" Fill="SkyBlue" HorizontalAlignment="Left" Height="30.073" Margin="98.625,-0.073,0,0" Stretch="Fill" UseLayoutRounding="False" VerticalAlignment="Top" Width="31.5"/>
<TextBlock Text="&#xE161;" FontFamily="Segoe Ui Symbol" Margin="10,0,0,0" FontSize="20" ></TextBlock>
<TextBlock Text="Configuration" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>
</Viewbox>

关于WPF 路径 : How to Draw this in XAML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23151297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com