我创建了一个消息框用户控件,圆角半径如下图,但是,我无法为此用户控件设置透明。请帮我。
非常感谢。
更新:
我已经按照你的说明实现了,但它仍然不是透明的,我认为背景的用户控件是白色的,请帮助我。下面是我的代码:
<UserControl x:Class="Nanote.TestDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="200"
Height="200" Width="450"
d:DesignWidth="300"
mc:Ignorable="d">
<Border CornerRadius="20" BorderBrush="Black" BorderThickness="10"
Background="Transparent">
<Rectangle Fill="White" Margin="10" />
</Border>
</UserControl>
最佳答案
考虑以下 XAML:
<Grid Background="Red">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Margin="20">
<Border CornerRadius="20" BorderBrush="Black" BorderThickness="10"
Background="Transparent">
<Rectangle Fill="White" />
</Border>
</Grid>
<Grid Grid.Row="1" Margin="20">
<Rectangle Fill="White" />
<Border CornerRadius="20" BorderBrush="Black" BorderThickness="10"
Background="Transparent" />
</Grid>
<Border Grid.Row="2" CornerRadius="20" BorderBrush="Black" BorderThickness="10"
Background="White" Margin="20">
<Rectangle Fill="White" Margin="10" />
</Border>
</Grid>
这会产生以下输出:
希望你现在可以从这个例子中找出你自己的解决方案。
关于wpf - 如何在wpf中为用户控件设置透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524172/