Load On Demand With Wcf Service ..

2 posts, 0 answers
  1. Ahmet HOSO
    Ahmet HOSO avatar
    12 posts
    Member since:
    Aug 2009

    Posted 21 Nov 2013 Link to this post

    Hi,

    I try to make a simple explorer. I want to show folders and files in a list and if item is not file, it will be expandable. I want to load expanding folder content from wcf service on demand .

    I can fetch data from service when folder expanded but can not show data under the related folder.

    Please tell me, what's wrong with my code.

    Here is the Page Code :
        public WebdiscPage()
        {
            InitializeComponent();
            this.Loaded += WebdiscPage_Loaded;
            this.Unloaded += WebdiscPage_Unloaded;
        }
     
        void WebdiscPage_Loaded(object sender, RoutedEventArgs e)
        {
            WebDiscService.WebDiscClient client = new WebDiscService.WebDiscClient();
            client.ListItemsInWebdiskFolderCompleted += client_ListItemsInWebdiskFolderCompleted;
            client.ListItemsInWebdiskFolderAsync(this.SessioID, this.UserID, "/", "Name", true);
        }
     
        void client_ListItemsInWebdiskFolderCompleted(object sender, WebDiscService.ListItemsInWebdiskFolderCompletedEventArgs e)
        {
            if (!e.Result.IsValid) return;
     
            ObservableCollection<WebdiskItemExtend> myList = new ObservableCollection<WebdiskItemExtend>();
            foreach (var item in e.Result.ListOfItemsInFolder)
            {
                myList.Add(new WebdiskItemExtend(item.IsFile, item.IsItemUserDefined, item.WebdiskItemDate, item.WebdiskItemName, item.WebdiskItemPath, item.WebdiskItemSize));
            }
            tlvWebdisc.ItemsSource = myList;
        }
     
        WebdiskItemExtend rowWebDiscItem; Telerik.Windows.Controls.GridView.GridViewRowItem row;
        private void tlvWebdisc_RowIsExpandedChanging(object sender, Telerik.Windows.Controls.GridView.RowCancelEventArgs e)
        {
            if (e.Row.DataContext != null)
            {
                row = e.Row;
                rowWebDiscItem = (WebdiskItemExtend)e.Row.DataContext;
                if (!rowWebDiscItem.IsExpanded && !rowWebDiscItem.IsFile)
                {
                    WebDiscService.WebDiscClient client = new WebDiscService.WebDiscClient();
                    client.ListItemsInWebdiskFolderCompleted += client_ListItemsInWebdiskFolderCompleted2;
                    client.ListItemsInWebdiskFolderAsync(this.SessioID, this.UserID, rowWebDiscItem.WebdiskItemPath, "Name", true);
     
                }
            }
        }
     
        void client_ListItemsInWebdiskFolderCompleted2(object sender, WebDiscService.ListItemsInWebdiskFolderCompletedEventArgs e)
        {
            if (!e.Result.IsValid) return;
              
            ObservableCollection<WebdiskItemExtend> myList = new ObservableCollection<WebdiskItemExtend>();
            foreach (var item in e.Result.ListOfItemsInFolder)
            {
                myList.Add(new WebdiskItemExtend(item.IsFile, item.IsItemUserDefined, item.WebdiskItemDate, item.WebdiskItemName, item.WebdiskItemPath, item.WebdiskItemSize));
            }
     
            rowWebDiscItem.WebdiskItemList = myList;
            rowWebDiscItem.IsExpanded = true;
        }
     
    }

    Here is the extended service response class
    public class WebdiskItemExtend : WebDiscService.WebdiskItem ,  INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private bool isExpanded;
     
        public bool IsExpanded
        {
            get
            {
                return this.isExpanded;
            }
            set
            {
                if (value != this.isExpanded)
                {
                    this.isExpanded = value;
                    this.OnPropertyChanged("IsExpanded");
                }
            }
        }
     
        protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, args);
            }
        }
     
        private void OnPropertyChanged(string propertyName)
        {
            this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }
     
        public ObservableCollection<WebdiskItemExtend> WebdiskItemList { get; set; }
     
        public WebdiskItemExtend() { }
        public WebdiskItemExtend(bool isFile, bool isItemUserDefined, DateTime webdiskItemDate, string webdiskItemName, string webdiskItemPath, string webdiskItemSize) { IsExpanded = false; IsFile = isFile; IsItemUserDefined = isItemUserDefined; WebdiskItemDate = webdiskItemDate; WebdiskItemName = webdiskItemName; WebdiskItemPath = webdiskItemPath; WebdiskItemSize = webdiskItemSize; WebdiskItemList = new ObservableCollection<WebdiskItemExtend>(); }
    }

    And Here is the xaml code

    <Grid Grid.Row="2" Grid.Column="2">
               <Grid.Resources>
                   <telerik:InvertedBooleanConverter x:Key="c" />
               </Grid.Resources>
               <telerik:RadTreeListView x:Name="tlvWebdisc" telerik:StyleManager.Theme="Windows8"
                                    IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
                                    IsExpandableBinding="{Binding IsFile, Converter={StaticResource c}}"
                                    AutoGenerateColumns="False"
                                    ShowColumnHeaders="False"
                                    MinHeight="386"
                                    ColumnWidth="*"
                                    CanUserFreezeColumns="False"
                                    IsReadOnly="True"
                                    RowIndicatorVisibility="Collapsed"
                                    RowIsExpandedChanging="tlvWebdisc_RowIsExpandedChanging"
                                        >
                   <telerik:RadTreeListView.ChildTableDefinitions>
                       <telerik:TreeListViewTableDefinition ItemsSource="{Binding WebdiskItemList}" />
                   </telerik:RadTreeListView.ChildTableDefinitions>
                   <telerik:RadTreeListView.Columns>
                       <telerik:GridViewDataColumn DataMemberBinding="{Binding WebdiskItemName}" IsReadOnly="True" Width="*" />
                       <telerik:GridViewDataColumn DataMemberBinding="{Binding WebdiskItemDate}" IsReadOnly="True" Width="150" />
                       <telerik:GridViewDataColumn DataMemberBinding="{Binding WebdiskItemSize}" IsReadOnly="True" Width="150" />
                   </telerik:RadTreeListView.Columns>
               </telerik:RadTreeListView>
           </Grid>

    Thanks
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 26 Nov 2013 Link to this post

    Hi Ahmet,

    There was a problem with the Q3 version in our TreeList control. May I ask you to try this out with our Latest internal build? 

    Let me know if the issue still persist! 

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top