UXTreeList树型控件如何设置数据的按需加载

作者:控件中国网   出处:控件中国网   2016-05-18 11:40:50   阅读:6

UXTreeList是包含在WebUI Studio for Silverlight和WPF下(又名ClientUI)下的一款树型控件,可以帮助开发人员在Silverlight或WPF下对多层数据采用树型的结构显示,使用该控件可以直观方便地显示复杂的多层数据,可以与多种数据源进行绑定,可以与UXGridView控件整合从而显示树型表格,可以对节点进行拖拉操作,为节点添加复选框等,这篇文章文章主要介绍如何对树型节点中的控件进行数据的按需加载,具体如下:
UXTreeList[1].png
C#:
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using ClientUI._2012R1.Preview.ModelServices;
using ClientUI._2012R1.Preview.Web;
using Intersoft.Client.Data.ComponentModel;
namespace ClientUI._2012R1.Preview.ViewModels
{
    public class LoadOnDemandViewModel : GridViewModelBase<Employee>
    {
        #region Constructors
        public LoadOnDemandViewModel()
        {
            this.QueryDescriptor.SuspendQueryChanged = true;
            this.QueryDescriptor.FilterDescriptors.Add(new FilterDescriptor() { PropertyName = "ReportsTo", Operator = FilterOperator.IsEqualTo, Value = null });
            this.QueryDescriptor.SuspendQueryChanged = false;
            this.LoadData();
        }
        #endregion
        #region Data Source
        private IDataRepository _dataSource;
        protected override IDataRepository DataSource
        {
            get
            {
                if (_dataSource == null)
                    _dataSource = new EmployeesRepository(RepositoryManager.Create());
                return _dataSource;
            }
        }
        #endregion
        #region Fields
        private object _expandedItem;
        private object _processedItem;
        #endregion
        #region Properties
        public object ExpandedItem
        {
            get { return _expandedItem; }
            set
            {
                if (_expandedItem != value)
                {
                    _expandedItem = value;
                    this.OnPropertyChanged("ExpandedItem");
                    this.LoadChildData(value as Employee);
                }
            }
        }
        public object ProcessedItem
        {
            get { return _processedItem; }
            set
            {
                if (_processedItem != value)
                {
                    _processedItem = value;
                    this.OnPropertyChanged("ProcessedItem");
                }
            }
        }
        #endregion
        #region Methods
         
        protected override void InitializeItems(IEnumerable items)
        {
            this.Items = new HierarchicalCollectionView(new ObservableCollection<Employee>(items.Cast<Employee>())); ;
        }
        private void LoadChildData(Employee employee)
        {
            if (employee != null)
            {
                Intersoft.Client.Data.ComponentModel.QueryDescriptor queryDescriptor = new Intersoft.Client.Data.ComponentModel.QueryDescriptor();
                queryDescriptor.FilterDescriptors.Add(new FilterDescriptor() { PropertyName = "ReportsTo", Operator = FilterOperator.IsEqualTo, Value = employee.EmployeeID });
                this.DataSource.GetData
                (
                    queryDescriptor,
                    (items) =>
                    {
                        this.ProcessedItem = employee;
                        HierarchicalCollectionView view = this.Items as HierarchicalCollectionView;
                        view.AddItems(items);
                    },
                    (totalItemCount) =>
                    {
                    },
                    (error) =>
                    {
                        this.Presenter.ShowErrorMessage(
                            "An exception has occurred during data loading.\n" +
                            "Message: " + error.Message + "\n" +
                            "Stack Trace: " + error.StackTrace);
                    }
                );
            }
        }
        #endregion
    }
}
XAML:
<Intersoft:UXPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:Intersoft="http://intersoft.clientui.com/schemas"
    xmlns:ViewModels="clr-namespace:ClientUI._2012R1.Preview.ViewModels"
    x:Class="ClientUI._2012R1.Preview.Views.UXTreeList.LoadOnDemand"
    Title="LoadOnDemand Page"
    d:DesignWidth="640" d:DesignHeight="480">
    <Intersoft:UXPage.DataContext>
        <ViewModels:LoadOnDemandViewModel/>
    </Intersoft:UXPage.DataContext>
    <Grid x:Name="LayoutRoot">
        <Intersoft:UXTreeList IsLoadOnDemand="True" ExpandedItem="{Binding ExpandedItem, Mode=TwoWay}" ProcessedItem="{Binding ProcessedItem, Mode=TwoWay}"
                              ItemsSource="{Binding Items}" IDBinding="{Binding EmployeeID}" ParentIDBinding="{Binding ReportsTo}"
                              AutoGenerateColumns="False" IsBusy="{Binding IsBusy, Mode=TwoWay}">
            <Intersoft:UXTreeList.Columns>
                <Intersoft:UXTreeListTreeColumn Header="Employee ID" Binding="{Binding Address}"/>
                <Intersoft:UXGridViewTextColumn Header="First Name" Binding="{Binding FirstName}"/>
                <Intersoft:UXGridViewTextColumn Header="Last Name" Binding="{Binding LastName}"/>
                <Intersoft:UXGridViewTextColumn Header="Address" Binding="{Binding Address}"/>
                <Intersoft:UXGridViewTextColumn Header="Home Phone" Binding="{Binding HomePhone}"/>
            </Intersoft:UXTreeList.Columns>
        </Intersoft:UXTreeList>
    </Grid>
</Intersoft:UXPage>
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat