c# - 如何以圆角 WPF 形式创建圆角矩形?
问题描述
我正在 WPF 中创建一个应用程序,我想要圆角。收到。现在表单是无边界的,我正在尝试创建一个圆角矩形并将其放在顶部,使其看起来像 Windows 应用程序的顶部栏。
我无法这样做。
这是我的代码:
<Border CornerRadius="50, 0, 50, 0" BorderBrush="Black" BorderThickness="2" Background="GhostWhite">
<Grid Margin="0,0,0,402">
<Rectangle HorizontalAlignment="Left" Height="44" VerticalAlignment="Top" Width="796">
<Rectangle.Fill>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<Border Width="800" Height="200" CornerRadius="50,0,0,0" Background="DarkOliveGreen"/>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
<Grid HorizontalAlignment="Left" Height="403" Margin="0,44,0,-403" VerticalAlignment="Top" Width="796"/>
</Grid>
</Border>
我的主要形式:
我得到了什么:
解决方案
你需要对你的控制结构做一些小的改变来实现它。以下代码经过测试并且可以正常工作。
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=myBorder}" />
</Grid.OpacityMask>
<Border x:Name="myBorder" CornerRadius="50,0,50,0" Background="GhostWhite" BorderBrush="Black" BorderThickness="2"/>
<Rectangle HorizontalAlignment="Left" Height="44" VerticalAlignment="Top" Width="796">
<Rectangle.Fill>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<Border Width="800" Height="200" CornerRadius="50,0,0,0" Background="DarkOliveGreen"/>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
推荐阅读
- excel - 如果另一个工作表中的范围小于下面的单元格,则撤消 ActiveSheet 中的更改
- python - Python正则表达式:可选
- python - 将锯齿状数组转换为 Pandas 数据框
- swiftui - 在 SwiftUI 和 macOS 11 中获取多行 + 可滚动 TextView 中子字符串的 X/Y 位置
- html - 可以将 table-sm 类与数据表一起使用吗?
- html - 如何通过单击按钮进行转换
- python - 在具有分类变量和连续变量的高维数据集上使用凝聚层次聚类
- javascript - 重新运行将 Google Sheet 数据注入 Google 幻灯片的脚本时,如何清除所有现有数据?
- javascript - 如何修复 Node JS 错误在 heroku 上找不到模块“express”?
- javascript - 火库!如何通过 javascript 代码从数组中删除地图?