如何在WPF中创建透明用户控件?

时间:2022-09-02 11:58:25

I have a WPF app with an image over which is laid a user control. I would like the user control background to be transparent but the buttons etc on that user control to be solid.

我有一个WPF应用程序,其上有一个用户控件。我希望用户控制背景是透明的,但用户控件上的按钮等是可靠的。

The image below shows what I have now. I would like to have the inside of the red area as transparent (the user control can in theory be many different shapes) but with the controls contained within it, solid.

下图显示了我现在拥有的内容。我希望红色区域的内部是透明的(理论上用户控件可以是许多不同的形状),但其中包含的控件是实心的。

如何在WPF中创建透明用户控件?

The main window XAML is;

XAML的主窗口是;

<Canvas Height="450" Width="300">
    <Border Opacity=".2" >
        <Image Source="D:\\BarbourCoat.jpg" Width="300" ></Image>
    </Border>
    <local:UserControl1 Height="100" Canvas.Left="10" Canvas.Top="10" Width="100"/>
</Canvas>

Whilst the user control XAML is;

用户控制XAML的同时;

<Canvas Background="Transparent">
    <Path Data="M 10 10 L 100 10 L 250 50 L 280 200 L 180 250 L 25 270 Z" Stroke="Red"></Path>
    <Button Content="Button" HorizontalAlignment="Left" Margin="41,53,0,0" VerticalAlignment="Top" Width="75"/>
    <TextBox HorizontalAlignment="Left" Height="23" Margin="90,112,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
    <TextBlock HorizontalAlignment="Left" Margin="69,209,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
</Canvas>

I'm having a hard time getting my head round this, any help would be greatly appreciated.

我很难理解这一点,任何帮助都将非常感激。

1 个解决方案

#1


5  

In XAML, have you made the whole UserControl transparent?

在XAML中,您是否使整个UserControl透明化?

<UserControl Background="Transparent">

#1


5  

In XAML, have you made the whole UserControl transparent?

在XAML中,您是否使整个UserControl透明化?

<UserControl Background="Transparent">