We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
In the previous month I have written an article about how to design a WPF custom context menu. I really liked that article because the outcome was very nice. Here comes the but :), as it turns out my implementation had a big disadvantage, it lacked the ability to show sub menus (an important trait in my opinion). So it was back to the drawing board for me.
After studying the WPF MenuItem Class and its Original Microsoft Template using blend. I learned some new things
Lets look at the code for one MenuItem object:
I have inserted a TextBlock inside the header so I can control better the Alignment, and into the Image I have inserted a Border with an Image in it. The Border will provide the gray background to all the Images. Of course there is a style also here it is:
Check out the Is Highlighted Trigger, that’s another thing I found out while researching the MenuItem Class.
The out come is this:
Pretty nice no? And the sub menus are back! And the most important thing: No DataTemplate or ControlTemplates used. All the natural behavior of the WPF Context Menu is preserved. To download a Full Code Example Just grab our feed to get the password to the Freebies page.
Tags :BlendContext MenuHeadericonMenuItem ClassSubMenuWPF
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd