Search code examples
c#wpfwinformstransparencyelementhost

Hosting WPF UserControl in a transparent Windows.Form


I need to insert my WPF USerControl into a Windows.Form. This is my control:

<UserControl x:Class="WpfControlLibrary1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Background="Transparent">

    <InkCanvas x:Name="Ink" Background="Transparent" />

</UserControl>

To host this control I use an ElementHost object as the only one control of my Form. I need to have the possibility to do the following: when I set the opacity of the form to 0, in order to make it invisible, I need to continue to have the opacity of all the Children and Strokes of My InkCanvas to 1 (so I can see them).

I tried using the TransparencyKey property, but it seems it doesn't work with the ElementHost. How can I solve this problem, and how can I set a different opacity between my Form and my UserControl?


Solution

  • AFAIK that's not possible as WPF use Subpixel alpha rendering which is not available with winform for example

    Hope this help