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“多选”,显示效果较差。

  • 相关阅读:
    为什么你应该(从现在开始就)写博客
    ASP.net 中使用Flexigrid详细教程之二直接使用数据库数据(有图有真相)
    保护眼睛的方法 (眼睛累了吗 来看看吧)
    程序员不如快递员?
    项目管理界面
    地址栏射击游戏!对,你没看错,就是在地址栏上玩的游戏,有图有真相!
    书写是为了更好的思考
    IT人员如何找到自己的时间?
    std::mem_fun_ref,mem_fun1_ref分析
    __declspec(selectany) 的作用是什么
  • 原文地址:https://www.cnblogs.com/super86/p/2755790.html
Copyright © 2011-2022 走看看