zoukankan      html  css  js  c++  java
  • RadTreeView按需加载

    XML:

    .....

    LoadOnDemand="ExplorerTreeView_LoadOnDemand"

    >

    后台代码:

    private void ExplorerTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;            
                if (item.Item is VoyageVO)
                {
                    var voyage = item.Item as VoyageVO;                
                    ObservableCollection<LegVO> Legs = new ObservableCollection<LegVO>();

                    if (item != null && item.Items.Count < 1)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            Legs = _IndoorSampleCheckHttpProxy.GetLegsByVoyageID(voyage.ID);
                            if (Legs == null) return;
                            //voyage.Legs.AddRange(Legs);
                            Application.Current.Dispatcher.Invoke(new Action(delegate()
                            {
                            item.ItemsSource = Legs;
                            }));
                        })
                        .ContinueWith((t) =>
                        {                        
                            Application.Current.Dispatcher.Invoke(new Action(delegate()
                            {
                                if (Legs.Count == 0)
                                    item.IsLoadOnDemandEnabled = false;                                
                                else
                                    item.IsLoadingOnDemand = false;
                            }));
                        });
                    }
                }
                else if (item.Item is LegVO)
                {
                    var leg = item.Item as LegVO;
                    ObservableCollection<StationVO> Stations = new ObservableCollection<StationVO>();
                    if (item != null && item.Items.Count < 1)
                    {
                        StationQueryInformation stationQueryInformation = new StationQueryInformation();
                        stationQueryInformation.LegID = leg.ID;
                        Task.Factory.StartNew(() =>
                        {
                            Stations = _IndoorSampleCheckHttpProxy.GetStationsByLeg(stationQueryInformation);
                            //leg.Stations.AddRange(Stations);
                            Application.Current.Dispatcher.Invoke(new Action(delegate()
                            {
                                item.ItemsSource = Stations;
                            }));
                        })
                        .ContinueWith((t) =>
                        {
                            item.Dispatcher.Invoke(new Action(delegate()
                            {
                                if (Stations.Count == 0)
                                    item.IsLoadOnDemandEnabled = false;
                                else
                                    item.IsLoadingOnDemand = false;
                            }));
                        });
                    }
                }
            }

    标记部分为:两种操作都能达到目的,前一种会造成TreeViewItem“多选”,显示效果较差。

  • 相关阅读:
    对匿名函数的深入理解(彻底版)
    彻底理解js中this的指向,不必硬背。
    JavaScript中call,apply,bind方法的总结。
    再次讲解js中的回收机制是怎么一回事。
    关于在for循环中绑定事件打印变量i是最后一次。
    深入作用域之静态作用域与动态作用域
    理解js中的自由变量以及作用域的进阶
    使用WeihanLi.Npoi操作Excel
    基于 HtmlHelper 的自定义扩展Container
    JSON.Net 自定义Json序列化时间格式
  • 原文地址:https://www.cnblogs.com/super86/p/2755790.html
Copyright © 2011-2022 走看看