Create a fully transparent WPF window to capture mouse events - wpf

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?

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.

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

Just set Background=Brushes.Transparent instead of Background=null.
You don't need to use opacity at all (ie. just leave it at 100% opacity).

For example i think your control name is MyGrid and you want it be Transparent and always get MouseOverEvent.....
If (window AllowsTransparency is True and the window Background is Transparent) Then
use a color like #01777777 for MyGrid Background Or 0.01 for MyGrid Opacity.
Else
use something like #00777777 for MyGrid Background Or 0.00 for MyGrid Opacity.

Setting the opacity to 100% (or any non-zero value), and the background to Transparent (instead of null) should make most controls hittable.
Make sure to set IsHitTestVisible to true. Not all controls can be hit, even if the opacity is 100% and the background is transparent.

You might find it simpler to use Mouse.Capture.
https://msdn.microsoft.com/en-us/library/ms771301.aspx
When an object captures the mouse, all mouse related events are treated as if the object with mouse capture perform the event, even if the mouse pointer is over another object.

Related

prevent wpf window render black background without allowstransparency=true

I have some animations on a window that should be overall transparent and stretched over multiple screens.
I dont need the title bar or the background.
I would like to save resources.
When I set allowstransparency(bad for performance) to false the transparent background is rendered black.
Is there some lighter alternative to even prevent the window to render the background?
I did not find any thing on alternative rendering or windows. I see the window class inherits from Window : ContentControl, IWindowService but I guess I shouldnt look into that.
I dont have code to show accept at least that im using
<WindowChrome.WindowChrome>
<WindowChrome
CaptionHeight="0"
ResizeBorderThickness="0"
/>
</WindowChrome.WindowChrome>
To disable transparency paddings on a loose window without allowstransparency=true.
One of the things WindowChrome gives you is the ability to add certain Windows window's abilities to a custom design window you make.
Not necessarily related to transparent background.
If you want your window to have round edges you will need to set AllowTranspareny to True, otherwise you will get the black background, no way around that.

Need overlapping button in round cornered Winform

Need a quick suggestion for styling a WinForm. I made it with rounded corners even when re-sized. Now trying to add a close button with a image (ControlBox=false), overlapping or clipped to top right corner. This is what I could end with.
But I wish to make it more like in this example image.
How could I achieve this in WinForm.
Here's the trick : your window doesn't just end with the white part. It extends a little bit further. The close button comes under the 'extra' part. The other sides where the window appears to not be there is actually transparent...or in the case of the image, semi-transparent.
The glow effect is provided by the window. Set the TransparencyKey property of the window to Color.Magenta (its a convention as Magenta is the color least likely to be used in a window). Then set the background image to a white background with a little bit of Magenta in the edges. The Magenta will appear transparent when set as the background image.
Fiddle around with TransparencyKey and you'll understand what I mean
Winforms itself cannot provide this for you without outside manipulation of the windows,
because it still uses win32 windows classes in the background.
If you want transparancy in windows: see articles like:
Cool, Semi-transparent and Shaped Dialogs with Standard Controls
And the method in Win32 to do it:
SetLayeredWindowAttributes

Silverlight OOB-Application - set backgroundcolor of main window to transparent

I create a Silverlight OOB application in which I try to change the background color of the window transparent. I would like to use as wallpaper its own image. This is not square and therefore interferes with the white background color of the main window.
In the OutOfBrowserSettings I can put as the "Window Style" to "none ".
In WPF there are the two following window properties:
AllowsTransparency = "True"
Background = "Transparent"
Unfortunately, this does not seem to know about Silverlight, though! Does anyone know how I get the background color of the main window transparent?
Have you tried to set beackground to {x:Null}? Or maybe to set the alpha in color to 0 which means transparent. For example #00FFFFFF or #00000000.
This is not possible with the current version (4) of Silverlight.

WPF: Changing the look of a Surface Listbox "click-effect"

I'm changing the look of some Controls that I use in my Microsoft Surface Application at the moment. And today I'm working on a SurfaceListBox.
I have the template for it and already changed background and borders and other stuff.
But I really cannot find where I can change the color of the rectangle that appears on the ListBoxItem when you touch the ListBox. At the moment it's just white and I want to change that.
It's not something like the effect that you can see when the item is selected. I already found that and changed that so my selected item now appears in a different color. But the effect in the second when you touch the item stays white.
So where can I change this effect?
If you mean the bright, white highlight that happens when you press your finger against an item you should look into the SurfaceShadowChrome. It's used by (almost) all surface controls to give feedback when the user is pressing on a control.
It does have a Color property that you can modify to suit your needs. Apart from the color, and the tweaking of corner radius and shadow offset, it's not a very flexible decorator. But hopefully, you'll be able to make it do what you need.

silverlight invisible hit area

I would like to know how to make an invisible hit area in silverlight. I have created a UIelement leftmousebuttondown event that calls a planeprojectionfunction(this function rotates the UIelment on its X-axis). However as the element is rotated there is less surface area for the mouse to click on. Any ideas?
Use a canvas and set the opacity to 1%. It will increase CPU usage a little bit (usually not noticeable) but that's a quick and easy approach.
EDIT:
As KeithMahoney pointed out, don't forget to set the background to a brush with some color. Canvas by default does not have a background brush.

Resources