How to create a transparent user control in WPF?

I have a WPF application with an image over which a user control is installed. I would like the custom control background to be transparent, but buttons, etc. This user control was durable.

Below is the image that I have. I would like the inside of the red area to be transparent (user control can theoretically have many different shapes), but with the controls contained in it solid.

enter image description here

XAML main window:

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

So far, the XAML user control:

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

It’s hard for me to handle this, any help would be greatly appreciated.

+4
source share
1 answer

In XAML, did you make transparent transparent UserControl?

<UserControl Background="Transparent">

+5
source

Source: https://habr.com/ru/post/1438967/


All Articles