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
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");
}
}
....
Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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?
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.
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!
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