I'm new to both WPF and MVVM. I searched for a good way to dynamically create menus in the MVVM partern and, not finding anything to my liking, rolled my own solution. It works, but for some reason the Foreground (text) color of the menus is sometimes (just sometimes) not correct.
I was going to include a picture to demonstrate my problem, but I don't have enough street cred on StackOverflow to do that. I therefore will add a link so you can call up a picture.
http://img220.imageshack.us/img220/1912/badmenu.jpg
My lowest submenu displays correctly with a white foreground, but its parent menu forground turned to black and is almost impossible to read. If I had hard coded the menus then the parent's forground color would be white. If I move my mouse over the parent its text will switch back to white, an the submenu will become black.
Further, once I move my mouse away from the parent, all of its boolean properties (IsHighlighted, IsSubmenuOpen, etc...) become false, which surprised me because I would think they should stay true. The end result is I haven't been able to solve this with a style trigger.
Here is my XAML .
<Window.Resources>
<DataTemplate DataType="{x:Type src:ParentMenu}" >
<Menu >
<MenuItem Header="{Binding MenuName}"
ItemsSource="{Binding ChildMenuItems}" />
</Menu>
</DataTemplate>
<HierarchicalDataTemplate DataType="{x:Type src:ChildMenu}"
ItemsSource="{Binding ChildMenuItems}" >
<MenuItem Header="{Binding MenuName}" Command="{Binding Path=Command}" />
</HierarchicalDataTemplate>
' StackOverflow is masking my end tag for Window.Resources
<DockPanel>
<Menu DockPanel.Dock="Top" ItemsSource="{Binding Menus}" />
<Grid>
<!-- Add additional content here -->
</Grid>
</DockPanel>
Both ParentMenu and ChildMenu inherit from a common class that actually holds all the menus and exposes sub-menus through the ChildMenuItems collection. ChildMenuItems is a list of ChildMenu objects. My ViewModels exposes a list of ParentMenu objects.
There probably is a better way to accomplish what I want here. As I said before, I'm new to both WPF and MVVM and this is the best solution I could construct so far. Currently I have a workaround where I set the background color of all menus to another color so the black text is readable, but that looks goofy. Here is a URL showing what I mean. I would make it a link, but StackOverflow is limiting me to only one link.
img132.imageshack.us/img132/4160/bettermenu.jpg
Any suggestions on what I'm doing wrong and/or how to fix the display problem?