This is a migrated thread and some comments may be shown as answers.

Load On Demand With Wcf Service ..

1 Answer 19 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Ahmet HOSO
Top achievements
Rank 1
Ahmet HOSO asked on 22 Nov 2013, 12:15 AM
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

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 26 Nov 2013, 03:44 PM
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 >>
Tags
TreeListView
Asked by
Ahmet HOSO
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or