带圆角的 WPF 无边框应用程序
我创建了一个无边框的 WPF 应用程序,并且有一个我想作为背景的图像。我在“画图”中创建了图像,因此无法选择使角透明。我想让应用程序具有圆角,但我没有通过 XAML 获得预期结果。我尝试添加边框以获得所需的效果,但是当我运行应用程序时,图像仍然位于边框前面。这是我的代码。我做错了什么?
<Border BorderBrush="Black" CornerRadius="15,15,15,15" BorderThickness="1,1,1,1" Width="242" Height="426">
<Grid>
<Image Height="425" Name="image1" Stretch="Fill" Width="240" Source="/Test;component/Test.png" />
<Grid Height="334" HorizontalAlignment="Left" Margin="24,39,0,0" Name="grid1" VerticalAlignment="Top" Width="198" />
</Grid>
</Border>
I have created a WPF app that is borderless and have an image that I want to be my background. I created my image in Paint, so I did not have an option to make the corners transparent. I would like to make the application have rounded corners, but I am not getting the expect results with XAML. I have tried adding a border to get the desired effect but when I run the application, the image is still in front of the border. Here is my code. What am I doing wrong?
<Border BorderBrush="Black" CornerRadius="15,15,15,15" BorderThickness="1,1,1,1" Width="242" Height="426">
<Grid>
<Image Height="425" Name="image1" Stretch="Fill" Width="240" Source="/Test;component/Test.png" />
<Grid Height="334" HorizontalAlignment="Left" Margin="24,39,0,0" Name="grid1" VerticalAlignment="Top" Width="198" />
</Grid>
</Border>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
窗口中的这些设置将使其透明:
然后将边框的背景设置为图像:
these settings in the window will make it transparent:
and then just set the background of the Border to be the image:
我认为您需要将 ClipToBounds="True" 添加到图像中。
I think you need to add ClipToBounds="True" to the image.
这是一个特殊的边框,ClipToBounds 可以完美地工作。如果您将埃雷兹的答案中的“Border”更改为“ClippingBorder”,那么它应该可以工作。
您可以使用 http://www.developerfusion.com/tools/convert/ vb-to-csharp/ 如果您更喜欢 C#。
Here is a special border where ClipToBounds works perfectly. If you change in Erez's answer the "Border" to "ClippingBorder" then it should work.
And you can use http://www.developerfusion.com/tools/convert/vb-to-csharp/ if you like C# better.