Hello,
I am using xamRibbon and ApplicationMenu2010 in a MVVM application. In order to put configuration items (like user setting, system wide setting etc.) into the ApplicationMenu2010 I see following options:
1. Put the content directly in XAML of the shell window
Pro: Clear and easy
Con: The whole XAML loading is done at startup of the shell and the configuration might not be used in the current session.
2. Add the menu items in code behind:
Pro: Not loaded at startup
Con: On _OnOpened() all items are created -> slow
private void ApplicationMenu2010_OnOpened(object sender, RoutedEventArgs e) { ApplicationMenu2010 menu = (ApplicationMenu2010)sender;
if (menu.Items.Count > 0) { return; }
menu.Items.Add(new ApplicationMenu2010Item { Header = "Einstellungen" });
menu.Items.Add(new ApplicationMenu2010Item { Header = "Benutzereinstellungen", Content = new vBenutzerEinstellungen(new vmBenutzerEinstellungen()) }); menu.Items.Add(new ApplicationMenu2010Item { Header = "Systemweite Farben", Content = new vSystemweiteFarben(new vmSystemweiteFarben()) }); menu.Items.Add(new ApplicationMenu2010Item { Header = "Systemweite Einstellungen", Content = new vGlobalConfig(new vmGlobalConfig()) });}
I wonder if there is a possibility to create only the currently clicked it at the time its needed.
var pwditem = new ApplicationMenu2010Item { Header = "Test", Style = (Style)GlobalStyles.Instance["ApplicationMenuItem"] }; pwditem.SetBinding(ApplicationMenu2010Item.CommandProperty, new Binding("OpenConfigurationItem")); menu.Items.Add(pwditem);
private vTest OpenConfigurationItem() { View vTest; vTest= this.Container.GetInstance<AppFact.Infrastructure.MVVM.ViewBase>("vTest"); return vTest;}
I want to create the different views with configuration records only when they are really neded.
In addition: Is there a way to mark a ApplicationMenu2010Item as header without click function?
Thanks
Niko
Hello Niko,
I am not entirely sure I completely understand your requirement in this case, but it sounds like you are looking to generate your ApplicationMenu2010Item elements as needed, depending on the view that you have. If this impression is incorrect, please let me know as the following is based upon it.
In order to do this, I would recommend that you continue with the Opened event of the ApplicationMenu2010. In this event, you can clear the Items collection of your ApplicationMenu2010 (if needed) and check the current view in your application. If you store some information regarding the ApplicationMenu2010, such as a List of ApplicationMenu2010Item elements, you can then check that information or loop through that collection of ApplicationMenu2010Item elements and add them to your ApplicationMenu2010 menu. This should allow you to create a potentially different ApplicationMenu2010 view for each of your views.
As for marking an ApplicationMenu2010Item as a header without a click function, I suppose one thing you could do is mark the IsHitTestVisible property of the ApplicationMenu2010Item as "false." This would prevent any sort of mouse event from firing on it, although, you would also lose the highlight on mouse hover effect as well. Another thing you could try in this case is to utilize the PreviewMouseDown/Up events of the ApplicationMenu2010Item and mark them handled. This should prevent the internally handled MouseDown/Up event from going through, essentially marking your ApplicationMenu2010Item "unclickable."
I hope this helps. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hello Andrew,
the ApplicationMenu2010Items will always be the same.
I would to create and render the view only if the user has selected the specific MenuItem.
For example there is a menu with 5 Items;
Each item has view (in this case a usercontrol) to show and manage the data.
In most of the cases the user wont open all Items, mainly only one or two. Currently all Items are generated (all views and viewmodels for the menutitems).
I would like to have a XAML ApplicationMenu2010Items defined in XAML (or codebehind if neccessary).
a) The user clicks on the menu item
b) The view and the viewmodel for this specific menu item are created