---
title: "WPF: Opacity and the MouseEnter Event."  
description: "WPF: Opacity and the MouseEnter Event."  
author: "Anonymous User"  
published: 2013-07-15  
updated: 2013-07-15  
canonical: https://www.mindstick.com/forum/1289/wpf-opacity-and-the-mouseenter-event  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# WPF: Opacity and the MouseEnter Event.

Hi [Mindstick](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes)!

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](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) enters the shape with the [mouse](https://yourviews.mindstick.com/story/5122/the-story-behind-lord-ganesha-s-mouse-mushak), some [additional information](https://www.mindstick.com/forum/160484/error-failed-to-launch-debug-adapter-additional-information-may-be-available-in-the-output-window) should be displayed, but the [event handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question) [never](https://yourviews.mindstick.com/view/290/zoos-prisons-for-beings-who-have-never-committed-a-crime) gets called.

Is there a way to get MouseEnter [events](https://www.mindstick.com/blog/102/events-in-c-sharp) for all Shapes, [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) just the topmost one?

## Replies

### Reply by shreesh chandra shukla

Hell Alex Leblois!

With your layout only the topmost rectangle will raise MouseEnter [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london). 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.


---

Original Source: https://www.mindstick.com/forum/1289/wpf-opacity-and-the-mouseenter-event

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
