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

Binding columns to view model

3 Answers 99 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 21 Jan 2013, 11:50 PM
I'm currently evaluating TreeListViews from various vendors and am trying to determine if what I'm looking for is possible. We are using an MVVM model for our code. That being said I have a view model that has a collection of items. Each item has a collection of children and a collection of additional properties. Below is some sample code:

public class PsuedoClass
{
    public IObservableCollection<IBaseClass> Parents { get; set; }     
}
 
public class Parent : IBaseClass
{
    public String Name { get; set; }
    public IObservableCollection<IBaseClass> Children { get; set; }
    public IDictionary<string, string> OtherData { get; set; }
}
 
public class Child : IBaseClass
{
    public String Name { get; set; }
}
 
public interface IBaseClass
{
    String Name { get; set; }
}

Now obviously this code isn't complete, but I wanted to give you an idea of the basic structure. Now I want to display this in a TreeListView where each row has a choice of a couple templates, one template for if its a Parent, the other if its a child. And then I want the columns to be bound to the "OtherData" in the Parents class (Meaning, I want the Header to be the "Key" in the dictionary and the data to be the "Value" of the dictionary, or some similar structure).

What I would like to be able to do is something like this:
<UserControl ... >
    <UserControl.Resources>
        <DataTemplate x:Key="ChildItemTemplate">
            <TextBlock Text="{Binding Name}"/>         
        </DataTemplate>
     
        <HierarchicalDataTemplate x:Key="ParentItemTemplate"
                                  ItemsSource="{Binding Children}"
                                  ItemTemplate="{StaticResource ChildItemTemplate}">
            <TextBlock Text="{Binding Name}"/>
             
            <SomeHowDisplayTheRestOfTheColumns/>
             
        </HierarchicalDataTemplate>
    </UserControl.Resources>
 
    <telerik:RadTreeListView ItemsSource="{Binding Parents}"
                             Columns="{Binding SomePropertyThatExposesOurColumns}"
                             ItemTemplate="{StaticResource ParentItemTemplate}">   
    </telerik:RadTreeListView>
</UserControl>


Any insight into if this is possible with examples would be greatly appreciated. Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Jan 2013, 11:52 AM
Hi,

The TreeListView is designed to work with homogeneous data and it does not provide an API for defining the child rows differently than the parent ones. You could implement such a scenario with the RadGridView. Would that work for you better?
 

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Josh
Top achievements
Rank 1
answered on 22 Jan 2013, 04:15 PM
It seems there's a fairly tight coupling between the view and the view model which I'm not a fan of. I won't have child rows for all my parent items, yet it seems the Expander icon is always present regardless and the only suggestion I see in your documentation is to go to the code-behind and bring in knowledge of my domain to the view which isn't going to happen. Unless I'm missing something. Maybe you can give me a clean MVVM example of using these controls (if that's possible).
0
Dimitrina
Telerik team
answered on 23 Jan 2013, 10:44 AM
Hi,

Indeed this is how you can hide the expander. You can additionally check the approach from this post with RadGridView simulating TreeListView-like structure.  

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeListView
Asked by
Josh
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Josh
Top achievements
Rank 1
Share this question
or