The one that got away [Simple workarounds for a visual problem when toggling a ContextMenu MenuItem's IsEnabled property directly]
**
This blog has moved to a new location and comments have been disabled.
All old posts, new posts, and comments can be found on The blog of dlaa.me.
See you there!
Comments
Anonymous
May 04, 2010
I discovered this problem myself last week and came up with yet another simple solution. Whenever you set menuitem.IsEnabled, call VisualStateManager.GoToState() to enter the correct visual state. I also dim the menu item's icon if it is disabled: menuitem.IsEnabled = enabled; VisualStateManager.GoToState(menuitem, (enabled ? "Normal" : "Disabled"), true); if (menuitem.Icon is Image) (menuitem.Icon as Image).Opacity = (enabled ? 1.0 : 0.5);Anonymous
May 04, 2010
jimmccurdy, Good one! Not everyone remembers that it's possible to change a control's visual states from outside the control - myself included sometimes. ;) The Icon Opacity change you describe makes total sense to me, but I didn't do that by default because it's not consistent with the WPF ContextMenu's default behavior. Thanks for sharing another great workaround!Anonymous
June 29, 2010
Hey David. Nice post. I used the info related to the IsEnabled workaround and applied it in my custom control. Blog post here: technologywanderer.wordpress.com/.../creating-a-silverlight-4-filemenu-control-from-a-comboboxAnonymous
June 29, 2010
Florin, Very cool - thanks for sharing!Anonymous
July 16, 2010
jimmccurdy: Wicked great code! I was tearing my hair out, wondering what I was doing wrong. I tried the bounce, but it kept crashing my app the second time it got called. But with your code, problem solved! Now I can go home for the day.