如何将渲染剪辑在圆形边框内?
我正在尝试创建一个带有圆角的边框,并在其上半部分突出显示。我使用带有径向渐变的椭圆,与边框的上半部分重叠,以突出显示,但我不知道如何防止椭圆给边框的角着色。这是来自 Kaxaml 的屏幕截图:
这是 XAML 代码:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="DarkGray">
<Grid Width="256" Height="256">
<Border CornerRadius="16" Background="Black" Margin="4">
<Border Background="Gray" Margin="32">
<TextBlock Foreground="Black" Text="1" FontFamily="Trebuchet MS" FontSize="96pt"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Border>
<Border CornerRadius="16" ClipToBounds="True">
<Ellipse>
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Transparent" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="3" ScaleY="2" CenterX="128" CenterY="128"/>
<TranslateTransform Y="-235"/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
</Border>
<Border CornerRadius="16" BorderThickness="8" BorderBrush="Black"/>
</Grid>
</Page>
How can I stop the topcornerareasbeingaffected椭圆的阴影?
我尝试过使用 OpacityMask
,但我必须承认我并不真正了解如何使用它,特别是在椭圆形被转换以进行渲染的情况下。无论我尝试什么,椭圆要么完全消失,要么完全不受影响。
任何帮助将不胜感激。
提前致谢。
I'm trying to create a border with rounded corners and a highlight on its top half. I'm using an ellipse with a radial gradient, overlapping the top half of the border, to give the highlight, but I can't figure out how to prevent the ellipse coloring the corners of the border. Here's a screenshot from Kaxaml:
And here's the XAML code:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="DarkGray">
<Grid Width="256" Height="256">
<Border CornerRadius="16" Background="Black" Margin="4">
<Border Background="Gray" Margin="32">
<TextBlock Foreground="Black" Text="1" FontFamily="Trebuchet MS" FontSize="96pt"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</Border>
<Border CornerRadius="16" ClipToBounds="True">
<Ellipse>
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Transparent" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="3" ScaleY="2" CenterX="128" CenterY="128"/>
<TranslateTransform Y="-235"/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
</Border>
<Border CornerRadius="16" BorderThickness="8" BorderBrush="Black"/>
</Grid>
</Page>
How can I stop the top corner areas being affected by the ellipse's shading?
I've tried playing around with OpacityMask
, but I have to confess I don't really understand how to use it, especially with the ellipse being transformed for rendering. Whatever I try, the ellipse either disappears entirely or is completely unaffected.
Any help would be greatly appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终没有使用
ClipToBounds
或OpacityMask
,而是使用径向渐变作为附加Border
元素的背景。感谢阿尔法鼠标的提示。这是最终的外观:
谢谢。
Instead of using
ClipToBounds
orOpacityMask
, I ended up using the radial gradient as the background to an additionalBorder
element. Thanks to alpha-mouse for the tip.And here's the final appearance:
Thanks.
首先,当我在 Visual Studio 中编译并运行代码时,它看起来很好。
其次,为什么不使用这个
RadialGradientBrush
作为第一个Border
的Background
?像这样的东西:First, it looks fine when I compiled and run you code in Visual Studio.
Second, why do not you use this
RadialGradientBrush
asBackground
of the firstBorder
? Something like this: