C # WPF transparency over Winform controls

I have a WPF control that I would like to apply to a WinForms application. Therefore, I dutifully created an element node that can display the following WPF object:

<UserControl x:Class="LightBoxTest.LightBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="300" Background="Transparent"> <Grid Name="dialogHolder" Background="Transparent" Opacity="1"> <Rectangle Name="rectangle1" Stroke="White" Fill="Black" RadiusX="10" RadiusY="10" Opacity="0.5" /> <StackPanel Name="stackPanel1" Background="Transparent" Height="300" VerticalAlignment="Top"> <Rectangle Name="spacer" Opacity="0" Stroke="Gray" Fill="White" RadiusX="10" RadiusY="10" Height="100" Width="300" /> <Grid Height="100" Name="contentHolder" Width="250"> <Rectangle Name="dialog" Stroke="Gray" Fill="White" RadiusX="10" RadiusY="10" Height="100" Width="250" /> </Grid> </StackPanel> </Grid> </UserControl> 

The problem is that the controls in the WinForm form are not displayed, and WPF just erases them on the screen.

An element host is created as follows:

 dialogHost = new ElementHost(); dialogHost.Child = dialog; dialogHost.BackColorTransparent = true; dialogHost.BringToFront(); dialogHost.Show(); 

Is there something I have to do, but Im not?

Are there any known issues with transparent WPF control over Winforms?

Any article that might help?

Note. This question is related to this question.

+7
c # controls winforms transparency wpf
source share
4 answers

I think you are faced with a problem of airspace . AFAIK, you cannot mix WPF transparency and ElementHost transparency, since ElementHost owns airspace.

There is a short message in the link about creating non-rectangular hwnds to host WPF content, and this may help you in the future.

Perhaps you can consider migrating more WinForms applications to WPF?

+6
source share

You should read the following: Black background before loading wpf controll when using ElementHost Just hide and show it (not cool, but it works)

+2
source share

You've probably tried this already, but what about setting transparency in the user control?

0
source share

This seems like an airspace issue.

0
source share

All Articles