Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a fully transparent WPF window to capture mouse events

I'm trying to trap mouse events in WPF by using a topmost, transparent non-modal window. I'm finding that this works fine if the opacity of the window is 0.01 or greater and it has a background color, but when the opacity is set to 0 it no longer receives mouse messages. Is there a way make this window look fully transparent and still get mouse input?

like image 818
James Cadd Avatar asked Oct 29 '09 20:10

James Cadd


2 Answers

As far as I know, no.

When a Control or Window is fully transparent, it can then be clicked through. This is the case if you set your Window.Background="Transparent", or Opacity="0". As far as I know, this is by design in WPF.

When using an opacity of 0.01, you should barely see the window, if at all. This is likely your best bet at achieving the functionality.

Edit: Another solution, which I tried and does work, is to set the background color to an almost-transparent color. I used Background="#01000000", thus giving an alpha value of 1. This makes your window background transparent-looking, but allows you to place controls on it with the window at full opacity.

like image 108
Will Eddins Avatar answered Nov 15 '22 23:11

Will Eddins


In Visual Studio 2010: Select your window in your design view.

Set the properties of your window to:

  • AllowsTransparency : check it
  • Background : Transparent
  • WindowStyle : None
like image 40
Sujith Avatar answered Nov 16 '22 00:11

Sujith