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

  • 相关阅读:
    使用 UDDI 的 Web 服务描述和发现(第一部分) 沧海
    软件配置管理(SCM) 沧海
    什么是WebService 沧海
    WSDL概述 沧海
    分析:对QQ、ICQ发展前景的判断 沧海
    软件巨头的高校人才之争 沧海
    读“我为什么不要应届毕业生” 沧海
    IT监控工作如何引入热门的ITIL? 沧海
    IT项目管理向沟通要效率 沧海
    闫成印:证券信息化未来需求分析 沧海
  • 原文地址:https://www.cnblogs.com/super86/p/2755790.html
Copyright © 2011-2022 走看看