XmlDocument在Silverlight中绑定到Treeview [英] XmlDocument bind to treeview in Silverlight

查看:57
本文介绍了XmlDocument在Silverlight中绑定到Treeview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我都面临着相同的问题
你能帮我这个忙吗?
我已经wcf返回了xelement并带有parent,child,subchild元素,我想将其绑定到treeview控件,就像parent,child,subchild元素一样,
请帮助我
这是wcf已从xelement重新启动,我要查找父级,子级,子级并绑定到silverlight4树视图.
在这里我得到对象引用未设置错误.

Hi All i am facing the same problem
can you please help me anybody on this.
I have wcf has returning the xelement with parents,child,subchild elements from that i want to bind to the treeview control as like parent,child ,subchild elements,
Please help me on this
this is wcf has retun as xelement from this i want to do find parent,child,subchild and bind to silverlight4 treeview.
here i am getting object reference not set error.

<?xml version="1.0" encoding="utf-8" ?>
<Regions>
  <Region name="Americas-01">
    <SubRegionOne name="LatinAmerica-05">
    </SubRegionOne>
    <SubRegionTwo name="MCA-60">
    </SubRegionTwo>
    <SubRegionThree name="CAC-37">
    </SubRegionThree>
    <Country name="HPEruope-14">
    </Country>
  </Region>
  <Region name="EMEA-02">
    <SubRegionOne name="LatinAmerica-05">
    </SubRegionOne>
    <SubRegionTwo name="MCA-60">
    </SubRegionTwo>
    <SubRegionThree name="CAC-37">
    </SubRegionThree>
    <Country name="HPEruope-14"></Country>
  </Region>
  <Region name="AsiaPacific-03">
    <SubRegionOne name="LatinAmerica-05">
    </SubRegionOne>
    <SubRegionTwo name="MCA-60">
    </SubRegionTwo>
    <SubRegionThree name="CAC-37">
    </SubRegionThree>
    <Country name="HPEruope-14"></Country>
</Region>
</Regions>


[DataContract]
    public class GeoDataProvider
    {
        [DataMember]
        public string Region { get; set; }
        [DataMember]
        public string SubRegionOne { get; set; }
        [DataMember]
        public string SubRegionTwo { get; set; }
        [DataMember]
        public string SubRegionThree { get; set; }
        [DataMember]
        public string Country { get; set; }
        [DataMember]
        public List<GeoDataProvider> GeoSubItems { get; set; }
    }     XDocument xDocument = XDocument.Load("Mpo_Admin.xml");
            GeoDatatSource = this.GetGeoSource(xDocument.Element("Regions"));
            GeotreeView.ItemsSource = GeoDatatSource;
        private List<GeoDataProvider> GetGeoSource(XElement element)
        {
            try
            {
                return (from Regiondata in element.Elements("Region")
                        select new GeoDataProvider()
                        {
                            Region = Regiondata.Attribute("name").Value,
                            SubRegionOne = Regiondata.Attribute("name").Value,
                            SubRegionTwo = Regiondata.Attribute("name").Value,
                            SubRegionThree = Regiondata.Attribute("name").Value,
                            Country = Regiondata.Attribute("name").Value,
                            GeoSubItems = this.GetGeoSource(Regiondata)
                        }).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

高级,谢谢,
问候,
Narasimha

Advanced thank you,
Regards,
Narasimha

推荐答案



在此文章

Hi,

In this Article,

categories = this.GetCategories(categoriesXML.Element("categories"));



而不是上面的行,像下面的一样使用



instead of the above line, use like the below one

categories = this.GetCategories(resultFromWCF); // resultFromWCF is XML Element returned from WCF


这篇关于XmlDocument在Silverlight中绑定到Treeview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆