D'Arcy from Winnipeg
Solution Architecture, Business & Entrepreneurship, Microsoft, and Adoption

Why Won’t My Silverlight Rectangle’s Mouse Enter Fire?

Monday, May 25, 2009 11:17 PM

I wanted to create an area in a Silverlight app that would react to the MouseEnter event. My first attempt looked something like this:


Don’t freak out about how I got the brushes window there…this is a paint.net smoke & mirrors image. I wanted to show what my settings were on my rectangle though. I figured that, since I didn’t want the rectangle to actually be visible, that I could just leave the fill and stroke values to be ‘No brush’.

But when I ran my app I noticed that my MouseEnter events weren’t firing. Odd…

After playing around a bit, I was able to get it working: I would set the fill and stroke colours to something, but alter the Opacity value under the Appearance property window to 0%. But this seemed like a hack: why would I need to set a totally different property just to enable the MouseEnter event for what was supposed to be a transparent rectangle?

Justin and Shawn were able to help me get to the true issue of the problem, and what a better solution was (thanks guys!).

The issue is with my brush, or in this case my lack of one. If you want to have a control be transparent but still react to events you still need to define a brush. So how do you assign a brush but still implement the transparency? By setting the value to #00000000


Notice now that for my fill and stroke brush I have the checkered pattern indicating transparency, not the ‘No brush’ text defined. I also didn’t need to touch the Opacity value either. Now when I mouse over my rectangle, the proper event fires.



# re: Why Won’t My Silverlight Rectangle’s Mouse Enter Fire?

Thanks very much for the usefull info. In fact it is sufficient to set the Fill of the rectangle just to Transparent. 3/16/2012 5:27 PM | Itzik

# re: Why Won’t My Silverlight Rectangle’s Mouse Enter Fire?

Man, you're a lifesaver...
Thanks a lot for sharing the tip!!! 5/30/2013 12:04 AM | Julianno

Post a comment