Binding columns to view model

4 posts, 0 answers
  1. Josh
    Josh avatar
    5 posts
    Member since:
    Jun 2012

    Posted 21 Jan 2013 Link to this post

    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.
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Jan 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Josh
    Josh avatar
    5 posts
    Member since:
    Jun 2012

    Posted 22 Jan 2013 Link to this post

    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).
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 23 Jan 2013 Link to this post

    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.

Back to Top