I don't have a quick solution in XAML. I needed get submenus items from database, according specific profiles, some users had all items others only 2 or 3 items. The unique way is create the menu in XAML with disabled items, pass the menu reference to ViewModel(if is MVVM App) and compare with the ObservableCollection, only the items equals are enabled:
<menu horizontalalignment="Left" height="27" verticalalignment="Top" width="649" name="menu1">
<menuitem header="_File">
<menuitem header="_Exit" command="{Binding ExitCommand}" />
</menuitem>
<menuitem header="_MyMenu">
<menuitem header="_SubMenu1" command="{Binding Command1}" isenabled="False" />
<menuitem header="_SubMenu2" command="{Binding Command2}" isenabled="False" />
</menuitem>
</menu>
ViewModel:
for (int i = 0; i < ObservableCollectionMenu.Count; i++)
{
for (int j = 0; j < ((MenuItem)menu1.Items[1]).Items.Count; j++)
{
if (((MenuItem)((MenuItem)menu1.Items[1]).Items[j]).Header.ToString().Equals(ObservableCollectionMenu[i].SubMenuColumn))
{
((MenuItem)((MenuItem)menu1.Items[1]).Items[j]).IsEnabled = true;
break;
}
}
}
I think that before the programmers had better support and help from codeproject.
Thanks.