C#解析Xaml
XmlDocument doc = new XmlDocument(); doc.Load(@"K:\Users\yuanchao\Documents\visual studio 2012\Projects\App3\App3\Dictionary1.xaml"); //XmlNode xn = doc.SelectSingleNode("bookste"); XmlNode xn = doc.ChildNodes[0]; XmlNodeList xnList = xn.ChildNodes; Dictionary<string, string> dictinoary = new Dictionary<string, string>(); foreach (XmlNode xnode in xnList) { string strKey = ""; string strBase = ""; foreach (XmlAttribute xmlatt in xnode.Attributes) { if (xmlatt.Name == "x:Key") { strKey = xmlatt.Value.ToString(); } if (xmlatt.Name == "BasedOn") { strBase = xmlatt.Value.ToString(); strBase = strBase.Replace("{StaticResource", "").Replace("}", "").Trim(); } } dictinoary.Add(strKey, strBase); } TreeViewItem itemheader = new TreeViewItem(); itemheader.Header = "Buttonstylebase"; TreeViewName.Items.Add(itemheader); foreach (KeyValuePair<string, string> str in dictinoary) { if (str.Value.ToString() == itemheader.Header.ToString()) { TreeViewItem item1 = new TreeViewItem(); item1.Header = str.Key.ToString(); itemheader.Items.Add(item1); } }
后台加载数据 在页面上显示出来
http://code.msdn.microsoft.com/windowsapps/Print-Sample-c544cce6