Quantcast
Viewing all articles
Browse latest Browse all 18858

Binding objects to a tree structure xaml

I am working on a WPF tree control. My class has objects which are a reference to another object. I want to be able to bind my objects in this class to be able to be bound to the tree in the xaml.

This is what I have in my ViewModel and I want to bind each to a tree structure :

 public List<AddressDataType> AddressDataVMField { get; set; }
        public List<NetworkContolType> NetworkControlVMField { get; set; }
        public List<IdentificationType> VehicleIdentificationVMField { get; set; }
        public List<PerformNewVehicleInquiryRequestType> PerformNewVehicleInquiryVMRequestField { get; set; }
}

here is the method to add data  to each node


        public List<PerformNewVehicleInquiryModel> getAllPerformNewVehicleInquiry()
        {
            // add to addressDataField List
            addressDataField.Add(new AddressDataType("AA", "A1"));
            addressDataField.Add(new AddressDataType("AA", "A1"));

            // add to networkControlField List
            //List<NetworkContolType> networkContolTypeList = new List<NetworkContolType>();
            networkControlField.Add(new NetworkContolType(addressDataField, "22", "1305231128040001 1UNISC"));

            // create and add to identificationType List
            List<IdentificationType> identificationTypeList = new List<IdentificationType>();
            identificationTypeList.Add(new IdentificationType("IdentificationType1"));
            identificationTypeList.Add(new IdentificationType("IdentificationType1"));

            // create and add to PerformNewVehicleInquiryRequestType List
            PerformNewVehicleInquiryRequestType performNewVehicleInquiryRequestType = new PerformNewVehicleInquiryRequestType(networkControlField, identificationTypeList);
            // add to list
            //List<PerformNewVehicleInquiryRequestType> performNewVehicleInquiryRequestTypeList = new List<PerformNewVehicleInquiryRequestType>();
            performNewVehicleInquiryRequestField.Add(performNewVehicleInquiryRequestType);

            // create and add to PerformNewVehicleInquiryModel
            performNewVehicleInquiryModel.Add(new PerformNewVehicleInquiryModel(addressDataField, networkControlField, identificationTypeList, performNewVehicleInquiryRequestField));

            return performNewVehicleInquiryModel;

        }

 // Bind tree to this observable list
        public ObservableCollection<PerformNewVehicleInquiryViewModel> PerformNewVehicleInquiries
        {
            get { return performNewVehicleInquiry; }
            set
            {
                if (performNewVehicleInquiry == value)
                    return;
                performNewVehicleInquiry = value;
                NotifyPropertyChanged("PerformNewVehicleInquiries");
            }
        }

I am having hard time to bind this to a tree structure.  it wont display the objects populated in the method above.

<TreeView Margin="644,137,6,6" Grid.RowSpan="2" ItemsSource="{Binding PerformNewVehicleInquiries}">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding}">
                        <HierarchicalDataTemplate.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding}">
                                <TextBlock Text="{Binding}"/>
                            </HierarchicalDataTemplate>
                        </HierarchicalDataTemplate.ItemTemplate>

                    </HierarchicalDataTemplate>
</TreeView.ItemTemplate>
            </TreeView>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>