I am using XamMenu for our primary application menu. Rather than hard code or add all the menus on the fly I want to use data binding. Our application menus are currently defined in XML. I can use linq to put them in an object graph if needed.
Reading the docs it talks about creating a hierarchal template but seems to say you need to create one for each menu level you need. Our menu structure is 100% defined in the XML.
First, is it possible to bind to XML or will I need to bind to an object graph.
Are there any examples of fully data driven XamMenus with random level depths.
BOb
Can anyone help me binding the XamMenu to an ObservableCollection in a ViewModel. I'm not quite sure how to set up the HierarchyTemplate object. I am just getting empty menus but I know the observable collection is getting populated.
Bob,
The XamDataTree will not be the best option. We may be able to get this to work now with the XamMenu with its current features. Please attach a sample XML file that you might use build a menu. I think we may be able to employ LINQ To XML to get this working.
Thanks,
Just following up on the sample I sent on Jan 24. Did you have any specific questions about that sample that I can assist with?
I'll give it a try. I assume if I add a fourth level of menus it will still display without having to modify the XAML?
Yes, this should work for n number of levels without modifying the XAML. Let me know if you have any other questions.
Ok a question.. all I get is text blocks in the menu. Shouldn't they be XamMenu items. I need to set the Header and NavigationUri along with a right click event handler. The "menu" displays but it doesn't do anything.
One of the developers informed me that we were neglecting to use the DefaultItemsContainer to host our DataTemplate for the XamMenuItem. An example is posted in our forums in a thread entitled "Horizontal XamMenu Data binding with Hierarchical Data" at this address: https://es.infragistics.com/community/forums/f/retired-products-and-controls/49840/horizontal-xammenu-data-binding-with-hierarchicaldata/264957#264957
I believe the proper markup in my own sample should be the following...
<ig:XamMenu Name="xamMenu1" ItemsSource="{Binding MenuItems }"> <ig:XamMenu.HierarchicalItemTemplate > <ig:HierarchicalDataTemplate ItemsSource="{Binding Children }"> <ig:HierarchicalDataTemplate.DefaultItemsContainer > <DataTemplate > <ig:XamMenuItem /> </DataTemplate > </ig:HierarchicalDataTemplate.DefaultItemsContainer > <ig:HierarchicalDataTemplate.ItemTemplate > <DataTemplate > <TextBlock Text="{Binding MenuTitle }"/> </DataTemplate > </ig:HierarchicalDataTemplate.ItemTemplate > <DataTemplate > <TextBlock Text="{Binding MenuTitle }"/> </DataTemplate > </ig:HierarchicalDataTemplate > </ig:XamMenu.HierarchicalItemTemplate > </ig:XamMenu >
The same XMAL worked to load the Menu items. but how this will work with the command.
I tried this way
<i:Interaction.Triggers> <i:EventTrigger EventName="ItemClicked"> <i:InvokeCommandAction Command="{Binding Path=SwitchPageCommand}" CommandParameter="{Binding Path=MenuName}" /> </i:EventTrigger> </i:Interaction.Triggers>
AND
<ig:XamMenuItem.InputBindings> <MouseBinding MouseAction="LeftClick" Command="{Binding Path=SwitchPageCommand}" CommandParameter="{Binding Path=MenuName}" /> </ig:XamMenuItem.InputBindings>
both the way but its not firing the event and not giving the parameter values. Can you help me on it