2

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?

Nick
  • 10,309
  • 21
  • 97
  • 201

3 Answers3

1

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

Hope this help

BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47
1

If you want to host a WPF control that behaves transparently on Win Forms, follow these steps

  • Create WPF usercontrol control and set background ="transparent".

  • Create Win User Control with no controls on it and write following code on its back end:

    public WinControl()
    {
        InitializeComponent();
    }
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
    
            cp.ExStyle |= 0x00000020;
            return cp;
        }
    }
    
  • Now place WPF usercontrol on Win user control and dock wpfusercontrol to its parent(win user control).

  • Now drag win user control on the |Win Form and dock win user control to its parent(Form)

And you are done.

RSB
  • 359
  • 5
  • 10
0

You could possibly use Microsoft.Ink.dll to create your own WinForms-based UserControl that supports handwriting recognition if that is what you are trying to do.

Nathan M
  • 873
  • 5
  • 18
  • Please, can you link any reference? – Nick Dec 20 '13 at 08:33
  • Sure. I hosted a small example using the Microsoft.Ink DLL, go to http://nmctl.codeplex.com, go to the source tree and download the InkSample directory. The Ink dll SHOULD be found in C:\Windows\assembly ... FYI there are quite a few libraries that Visual Studio doesn't automatically find that are available in that directory and also in C:\Windows\Microsoft.NET) ... – Nathan M Dec 20 '13 at 20:27