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
I've been pretty busy... I'm not sure how a sample of something that isn't working is going to help. ;)
Bob,
I'm sorry for not getting back to you. Have you made any progress since with a sample since 12/29, or do you need us to try to create one? I will keep my eye on this thread for your reply.
Thanks,
Francis,
I have implemented INotifyPropertyChanged in the view model. I have not in the MenuItem class since the menu items don't change.. just the collection (IList). I think I tried it both as an ObservableCollection and as the EntityCollection (that comes back from RIA.)
I have worked out the linq to XML to create the object graph. The code runs in my DomainService which returns the menu data as a List. Here is the code of our Menu service that creates the object graph from our menu xml:
namespace AmsiWeb.ConfigServices
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Xml.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
using System.Collections;
using System.Text.RegularExpressions;
using System.Xml;
[EnableClientAccess()]
public class MenuService : DomainService
int _menuIdIterator;
public IEnumerable<MenuItem> LoadTocBranch(string tocPath, string menuProvider)
XDocument xdoc = XDocument.Load(new XmlNodeReader(MenuHelper.GetMenu(tocPath, menuProvider)));
var menu = (from node in xdoc.Root.Elements("NODE")
select new MenuItem
Id = ++_menuIdIterator,
MenuTitle = (string)node.Attribute("text"),
NavigationUri = ParseUri((string)node.Attribute("navigate")),
IconPath = (string)node.Attribute("iconPath"),
NodeSource = (string)node.Attribute("nodeSrc"),
NodeProvider = (string)node.Attribute("nodeProvider"),
Children = GetNodeChildren(node.Elements("NODE"), node)
}).ToList<MenuItem>();
return menu;
}
private IList<MenuItem> GetNodeChildren(IEnumerable<XElement> elements, XElement parentNode)
var parentId = _menuIdIterator;
return (from node in elements
ParentMenuId = parentId,
/// <summary>
/// Pre-pend Html/ to any Uri that ends with .htm or .html or .aspx. This will facilitate the UriMapper and navigation in the silverlight client.
/// </summary>
/// <param name="Uri">The Uri to parse.</param>
/// <returns></returns>
private string ParseUri(string Uri)
if ((! String.IsNullOrEmpty(Uri)) && Regex.IsMatch(Uri, @"(.*?)\.(html|htm|aspx|asp)"))
return "Html/" + System.Web.HttpUtility.UrlEncode(Uri);
return Uri;
public class MenuItem
[Key]
public int Id { get; set; }
public string MenuTitle { get; set; }
public string NavigationUri { get; set; }
public string IconPath { get; set; }
public string NodeProvider { get; set; }
public string NodeSource { get; set; }
public int ParentMenuId { get; set; }
[Include]
[Composition]
[Association("Children","Id","ParentMenuId")]
public IList<MenuItem> Children { get; set; }
public MenuItem()
Children = new List<MenuItem>();
If I have time I will try to isolate this all into a single sample with what I was trying to do. I really need to get this working. Thanks.
I am having some difficulty parsing the XML since it is a nested strructure of the same kind of item (NODE), so I am looking further into that. In the mean time, I need to ask the following questions:
1. Are you implementing INotifyProprtyChanged on the MenuItem class and on the collection of type MenuItem? If not, then there may be some chance that you are bound to that object before it is actually hydrated....just a thought.
2. Can you provide a sample (isolating just the menu) that shows the issue whereby you are getting the empty menu while the XML data is in memory?
Thanks for the information. I am enlisting some help on implementing the LINQ to XML idea I had proposed. I hope to post a sample back here soon.