wpf - 如何在wpf中为用户控件设置透明

标签 wpf

我创建了一个消息框用户控件,圆角半径如下图,但是,我无法为此用户控件设置透明。请帮我。

非常感谢。

enter image description here

更新:

我已经按照你的说明实现了,但它仍然不是透明的,我认为背景的用户控件是白色的,请帮助我。下面是我的代码:

<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>

这会产生以下输出:

enter image description here

希望你现在可以从这个例子中找出你自己的解决方案。

关于wpf - 如何在wpf中为用户控件设置透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524172/

相关文章:

wpf - DockableFloatingWindow 上的最大化和 Aero 捕捉

c# - 单实例窗口 WPF 不工作

c# - 如何在 C#(3.0) 中从 wpf 窗口导航到 wpf 页面?

wpf - 如何仅使用 XAML 标记在单击另一个控件时打开 WPF 弹出窗口?

c# - Visual Studio 智能感知显示我的属性的自定义选项

c# - 按住修饰键时,所有 WPF 上下文菜单似乎都无法正确处理突出显示的项目

wpf - WCF/WPF 最佳实践 - WCF ChannelFactory 和 PRISM

c# - 如何在一个类中创建一组方法/属性?

c# - WPF UserControl 在代码中创建,绑定(bind)未注册 INotifyPropertyChanged

wpf - wpf切换按钮: Display text along with image as content