Home > DeveloperSection > Forums > WPF: Opacity and the MouseEnter Event.
lois waisbrooker
lois waisbrooker

Total Post:70

Points:494
Posted on    July-15-2013 3:54 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 1020  View(s)
Rate this:
Hello MindStick

c# wpf mouseevent opacity

As part of a diagram, I am drawing a few overlapping Shapes, each with Opacity=0.5, like here:

<Grid>
    <Rectangle Fill="Blue" Opacity="0.5" MouseEnter="Rectangle_MouseEnter" />
    <Rectangle Fill="Red" Opacity="0.5" />
</Grid>
 
private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
  {
     MessageBox.Show("Entered");
  }

When the user enters the shape with the mouse, some additional information should be displayed, but the event handler never gets called.

Is there a way to get MouseEnter events for all Shapes, instead of just the topmost one?

Thanks in advance.


shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-15-2013 7:59 AM

Hi  lois waisbrooker !
With your layout only the topmost rectangle will raise MouseEnter event. It fully overlaps the first rectangle.

Try this code for eventHandler:

private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
        {
            if (sender != grid.Children[0])
            {
                var rect = (grid.Children[0] as Rectangle);
                if (rect != null) rect.RaiseEvent(e);
            }
            else
            {
                MessageBox.Show("Entered.");
            }
        }
For this works you need to subscribe both rectangles to Rectangle_MouseEnter
 I hope it is help-full for you.

Don't want to miss updates? Please click the below button!

Follow MindStick