子控件意外改变不透明蒙版

发布于 2024-12-02 14:11:06 字数 709 浏览 5 评论 0原文

我想制作一块具有圆形边框的画布。我想我可以通过OpacityMask来实现它。但这对我来说很难。

<Canvas Background="Red" ClipToBounds="True" x:Name="can">
    <Canvas.OpacityMask>
        <!--czc.png is opacity mask source which represents a rounded rectangle.-->
        <ImageBrush ImageSource="/WpfApplication3;component/Images/czc.png"/>
    </Canvas.OpacityMask>
    <Image Source="/WpfApplication3;component/Images/1lvhuman.jpg" Margin="-129,56,192,46" Canvas.Left="193" Canvas.Top="25" Height="186" Width="153" />
</Canvas>

在此处输入图像描述

图 1. 是画布中未悬挂在画布边框中的图像。相反,图 2 的图像悬挂在 Canvas 的左边框中。当挂在那里时,OpacityMask 被改变了。

I want to make a canvas which has rounded border. I think I can implement it by OpacityMask. but it's a hard to me.

<Canvas Background="Red" ClipToBounds="True" x:Name="can">
    <Canvas.OpacityMask>
        <!--czc.png is opacity mask source which represents a rounded rectangle.-->
        <ImageBrush ImageSource="/WpfApplication3;component/Images/czc.png"/>
    </Canvas.OpacityMask>
    <Image Source="/WpfApplication3;component/Images/1lvhuman.jpg" Margin="-129,56,192,46" Canvas.Left="193" Canvas.Top="25" Height="186" Width="153" />
</Canvas>

enter image description here

figure 1. is the Image in canvas that don't hanged in the Canvas's border. In the contrary, the Image of figure 2 hanged in left border of the Canvas. when hanged in there, OpacityMask was changed.

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

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

发布评论

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

评论(1

木緿 2024-12-09 14:11:06

你为什么使用画布?您可以只使用带有 BorderRadius 的 Border 吗?

Why are you using Canvas? Can you just use a Border with a BorderRadius instead?

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