April 6th, 2011, 02:01 AM
WPF Controls and Transparency
I have Child Controls, MultiScaleImage's if that makes a difference, on my UserControl. The original images are landscape in orientation. I set an OpacityMask on the images using a RadialGradientBrush. This makes the images appear circular, which is what I want. Eg:
The issue I have is that I want my UserControl to fire Mouse* events when the User interacts with my Images. Unfortunately, as far as the mouse cursor is concerned, it still thinks my images are rectangular (landscape). So when the mouse cursor is just off to the left of the visible circular image, it still fires MouseMove events (for example). I only want the events to fire when the mouse cursor is over the visible part of the image. I was a bit disappointed, as in other parts of WPF, setting a background of Transparent suppresses these messages.
private Brush GetOpacityMask(double aspectRatio)
GradientStopCollection stopCollection = new GradientStopCollection();
// some other shapes
// Circle Shape
GradientStop stop1 = new GradientStop();
stop1.Color = Colors.Black;
stop1.Offset = 0.5 / aspectRatio;
GradientStop stop2 = new GradientStop();
stop2.Color = Colors.Transparent;
stop2.Offset = 0.5 / aspectRatio;
RadialGradientBrush brush = new RadialGradientBrush(stopCollection);
brush.RadiusX = 1.0;
brush.RadiusY = 1.0 * aspectRatio;
Is there a way this can be achieved?
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!