WPF Tree doesn't work

Posted by phenevo on Stack Overflow See other posts from Stack Overflow or by phenevo
Published on 2010-03-23T12:49:48Z Indexed on 2010/03/23 12:53 UTC
Read the original article Hit count: 573

Filed under:
|
|
|

Could you tell me why I can't see subItems?

I've got winforms apps and I added my wpfusercontrol:ObjectsAndZonesTree

ServiceProvider is my webservice. Adn method to get listofcountires with subitems works properly (i get countires, regions from this countires, provinces etc...)

 ElementHost elementHost = new ElementHost
                                          {
                                              Width = 150,
                                              Height = 50,
                                              Dock = DockStyle.Fill,
                                              Child = new ObjectsAndZonesTree()
                                          };


            this.splitContainer3.Panel1.Controls.Add(elementHost);

XAML:

<TreeView Name="GroupView" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding}">
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type ServiceProvider:Country
}" ItemsSource="{Binding Items}">
                <TextBlock Text="{Binding Path=Name}" />
                </HierarchicalDataTemplate>
            <DataTemplate DataType="{x:Type ServiceProvider:Region}" >
                <TextBlock Text="{Binding Path=Name}" />
                </DataTemplate>
            <DataTemplate DataType="{x:Type ServiceProvider:Province}" >
                <TextBlock Text="{Binding Path=Name}" />
                </DataTemplate>
        </TreeView.Resources>
    </TreeView>

XAML.CS

 public ObjectsAndZonesTree()
        {
            InitializeComponent();

            LoadView();
        }

        private void LoadView()
        {
            GroupView.ItemsSource = new ServiceProvider().GetListOfObjectsAndZones();

        }

class Country:

public class Country
    {
        string _name;

        [XmlAttribute]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        string _code;

        [XmlAttribute]
        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        string _continentCode;

        [XmlAttribute]
        public string ContinentCode
        {
            get { return _continentCode; }
            set { _continentCode = value; }
        }

        public Region[] ListOfRegions
        {
            get { return _listOfRegions; }
            set { _listOfRegions = value; }
        }

        private Region[] _listOfRegions;

        public IList<object> Items
        {
            get
            {
                IList<object> childNodes = new List<object>();
                foreach (var group in this.ListOfRegions)
                    childNodes.Add(group);

                return childNodes;
            }
        }



    }

Class Region:

public class Region {

private Province[] _listOfProvinces;
        private string _name;
        private string _code;

        public Province[] ListOfProvinces
        {
            get { return _listOfProvinces; }
            set { _listOfProvinces = value; }
        }

        public string Name
        {
            get {
                return _name;
            }
            set {
                _name = value;
            }
        }

        public string Code
        {
            get {
                return _code;
            }
            set {
                _code = value;
            }
        }

        public string CountryCode
        {
            get { return _countryCode; }
            set { _countryCode = value; }
        }

        private string _countryCode;

        public IList<object> Items
        {
            get
            {
                IList<object> childNodes = new List<object>();
                foreach (var group in this.ListOfProvinces)
                    childNodes.Add(group);

                return childNodes;
            }
        }
}

It displays me only list of countires.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf