Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# WPF transparency over Winform controls

I have a WPF control that I would like to overlay onto a WinForms application. So I have dutifully created a Element Host that can show 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 trouble is that the Controls on the WinForm Form do not render and the WPF just obliterates them on the screen.

The element host is created like:

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

Is there something I should be doing and Im not?

Are there known issues about showing transparent WPF controls over Winforms?

Any articals that may help?

Note: This question is related to this question

like image 825
TK. Avatar asked Jun 01 '09 20:06

TK.


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

I think you're running into an airspace issue. AFAIK, you can't mix WPF transparency and ElementHost transparency since the ElementHost owns the airspace.

There's a short blurb in the link about creating non-rectangular hwnds to host WPF content, and that may get you farther.

Perhaps you can consider migrating more of the WinForms app to WPF?

like image 151
micahtan Avatar answered Sep 19 '22 21:09

micahtan


You should read this :Black background before loading a wpf controll when using ElementHost Just hide & show it (not cool but works)

like image 40
qhuydtvt Avatar answered Sep 22 '22 21:09

qhuydtvt