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

How do I expand row from ViewModel when using Load On Demand?

5 Answers 178 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Rob Conley
Top achievements
Rank 1
Rob Conley asked on 13 Feb 2013, 03:27 AM
When I only have 1 row under certain conditions, I want to expand the row and show second level load on demand items (not 3rd or deeper).

I have populated my child collection in the ViewModel and have TwoWay binding set, but there must be another trick to getting the TreeListView to expand the row.

Any suggestions are appreciated.

-Rob

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 13 Feb 2013, 07:10 AM
Hello,

 The current official load on demand demo can be found here. With our upcoming official Q1 2013 release we will introduce two new properties (IsExpandedBinding and IsExpandableBinding) related to better MVVM, expand/collapse and load on demand for RadTreeListView. 

Here is an example code from our still unreleased demo:

<Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <telerik:InvertedBooleanConverter x:Key="c" />
        </Grid.Resources>
 <telerik:RadTreeListView ItemsSource="{Binding FoldersOnDemand}"
                                 IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
                                 IsExpandableBinding="{Binding IsEmpty, Converter={StaticResource c}}"
>
   <telerik:RadTreeListView.ChildTableDefinitions>
       <telerik:TreeListViewTableDefinition ItemsSource="{Binding Items}" />
    </telerik:RadTreeListView.ChildTableDefinitions>
 </telerik:RadTreeListView>
</Grid>
....
        private bool isExpanded;

        [Display(AutoGenerateField = false)]
        public bool IsExpanded
        {
            get
            {
                return this.isExpanded;
            }
            set
            {
                if (this.isExpanded != value)
                {
                    this.isExpanded = value;

                    this.LoadChildren();

                    OnPropertyChanged("IsExpanded");
                }
            }
        }

        public void LoadChildren()
        {
            if (this.items == null)
            {
                this.items = new ObservableCollection<FolderViewModel>(from f in this.folderElement.Elements("folder")
                                                                       select new FolderViewModel(f)
                                                                       {
                                                                           Name = f.Attribute("Name").Value,
                                                                           IsEmpty = bool.Parse(f.Attribute("IsEmpty").Value),
                                                                           CreatedOn = DateTime.Parse(f.Attribute("CreationTime").Value, System.Globalization.CultureInfo.InvariantCulture),
                                                                       });
                this.OnPropertyChanged("Items");
            }
        }
....

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rob Conley
Top achievements
Rank 1
answered on 13 Feb 2013, 02:20 PM
Thanks for the quick reply.

One thing that has confused me in the past examples is the use of the ViewModel class itself as the collection class or using a collection within the view model as the binding object in XAML. I once thought the ViewModel itself had to be a collection.

It works either way, correct? In other words, IsExpanded can be a property on the view model or on a collection within the ViewModel that the list is bound to in XAML, correct?
0
Vlad
Telerik team
answered on 13 Feb 2013, 04:22 PM
Hi,

The DataContext for both IsExpandedBinding and IsExpandableBinding is the data item associated with every row in the treelist. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mohammad
Top achievements
Rank 1
answered on 15 Jun 2019, 06:48 PM

Hi

Long time I did try to run and MVVM lazy loading of RadTreeListView. but I can not success in it!
I am Hopeless and dont know any solusion for it. 
I try and try ... but can not ...
Please help me!
I dont have Win 10 and dont access to WPF demos!


0
Martin Ivanov
Telerik team
answered on 18 Jun 2019, 08:21 AM
Hello Mohammad,

You can check the following two articles:

- Expand and Select Item with Load on Demand Enabled RadTreeView - This article shows how to implement lazy loading in MVVM.
- Load on Demand - This article shows the built-in load on demand feature.

I hope this helps.

Regards,
Martin Ivanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeListView
Asked by
Rob Conley
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rob Conley
Top achievements
Rank 1
Mohammad
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or