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

Binding problem with nested childtabledefinitions

6 Answers 348 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 26 Oct 2011, 10:46 PM
I'm using a RadTreeListView to display the following data (this is a mockup of the real business model):

Directory AAA
|__ SourceFile 001
                  |__ Function 001
                  |__ Function 002
|__ SourceFile 002
                  |__ Function 001
                  |__ Function 002
Directory BBB
|__ Directory BBB.1
                  |__ SourceFile 001
                                    |__ Function 001
|__ SourceFile 002
                  |__ Function 001
                  |__ Function 002

Model for these and the xaml are using are below:
// 1) Classes that define each of the levels (NodeItem being the base class)
 
    public class NodeItem
    {
        public string Name { get; set; }
        public string Path { get; set; }
    }
 
    public class SourceDirectoryItem : NodeItem
    {
        public SourceDirectoryItem()
        {
            this.Children = new ObservableCollection<NodeItem>();
        }
 
        public ObservableCollection<NodeItem> Children { get; set; }
    }
 
    public class SourceFileItem : NodeItem
    {
        public SourceFileItem()
        {
            this.Functions = new ObservableCollection<NodeItem>();
        }
 
        public ObservableCollection<NodeItem> Functions { get; set; }
    }
 
    public class FunctionItem : NodeItem
    {
    }
 
// 2) XAML
 
        <telerik:RadTreeListView
                AutoGenerateColumns="False"
                ItemsSource="{Binding Nodes}">
 
            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}">
 
                    <telerik:TreeListViewTableDefinition.ChildTableDefinitions>
                         
                        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}">
                            <telerik:TreeListViewTableDefinition ItemsSource="{Binding Functions}" />
                        </telerik:TreeListViewTableDefinition>
                         
                    </telerik:TreeListViewTableDefinition.ChildTableDefinitions>
                     
                </telerik:TreeListViewTableDefinition>
            </telerik:RadTreeListView.ChildTableDefinitions>
 
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="NAME">
 
                </telerik:GridViewDataColumn>
            </telerik:RadTreeListView.Columns>
             
        </telerik:RadTreeListView>
 
// 3) In the VM there is nothing special, this is how I populate the nodes:
 
        private void InitNodes()
        {
            SourceDirectoryItem root = new SourceDirectoryItem() { Name = "c:\\", Path = Name };
            SourceDirectoryItem firstLevel = new SourceDirectoryItem() { Name = "c:\\folder1", Path = Name };
            SourceDirectoryItem secondLevel01 = new SourceDirectoryItem() { Name = "c:\\folder1\\temp", Path = Name };
            SourceDirectoryItem secondLevel02 = new SourceDirectoryItem() { Name = "c:\\folder1\\programfiles", Path = Name };
            firstLevel.Children.Add(secondLevel01);
            firstLevel.Children.Add(secondLevel02);
            root.Children.Add(firstLevel);           
             
            SourceFileItem sf = new SourceFileItem();
            sf.Name = "foo.cs";
            sf.Path = "c:\\temp";
            sf.Functions.Add(new FunctionItem() { Name = "Method001" });
            sf.Functions.Add(new FunctionItem() { Name = "Method002" });
            sf.Functions.Add(new FunctionItem() { Name = "Method003" });
            secondLevel01.Children.Add(sf);
 
            SourceFileItem sf1 = new SourceFileItem();
            sf1.Name = "bar.cs";
            sf1.Path = "c:\\programfiles";
            sf1.Functions.Add(new FunctionItem() { Name = "AnotherMethod" });
            secondLevel02.Children.Add(sf1);
 
            this.Nodes.Add(root);
        }
 
        private ObservableCollection<NodeItem> nodes;
        public ObservableCollection<NodeItem> Nodes
        {
            get
            {
                return this.nodes;
            }
 
            set
            {
                this.nodes = value;
                this.OnPropertyChanged("Nodes");
            }
 
        }

So my issue is that if I leave the binding for Functions  in the XAML I get what you can see in pic 1 (issue.jpg) the third level directory entries are not expandable; if I remove that binding then I get the hierarchy working, of course up until the source file level (no_functions_binding.jpg).

Any idea what could be going on?

Thanks,
Jose


6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 31 Oct 2011, 04:35 PM
Hi Jose,

 You do not need to put any inner child table definitions. It would be enough to use this XAML definition:

<telerik:RadTreeListView
               AutoGenerateColumns="False"
               ItemsSource="{Binding Nodes}">
           <telerik:RadTreeListView.ChildTableDefinitions>
               <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}">
                 </telerik:TreeListViewTableDefinition>
           </telerik:RadTreeListView.ChildTableDefinitions>
           <telerik:RadTreeListView.Columns>
               <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="NAME">
               </telerik:GridViewDataColumn>
           </telerik:RadTreeListView.Columns>
       </telerik:RadTreeListView>

Is there some problem with this XAML definition in your case?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jose
Top achievements
Rank 1
answered on 31 Oct 2011, 05:46 PM
Thanks for the answer Didie, unfortunately it doesn't work, it shows the 'files' as children of directories but it won't show functions (children of the file object) as it's not included in the definition. That's why in my example I also used a child table definition for the Functions, see below:

<telerik:RadTreeListView
        AutoGenerateColumns="False"
        ItemsSource="{Binding Nodes}">
 
    <telerik:RadTreeListView.ChildTableDefinitions>
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}">
 
            <telerik:TreeListViewTableDefinition.ChildTableDefinitions>
                 
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}">
                    <telerik:TreeListViewTableDefinition ItemsSource="{Binding Functions}" />
                </telerik:TreeListViewTableDefinition>
                 
            </telerik:TreeListViewTableDefinition.ChildTableDefinitions>
             
        </telerik:TreeListViewTableDefinition>
    </telerik:RadTreeListView.ChildTableDefinitions>
 
    <telerik:RadTreeListView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="NAME">
 
        </telerik:GridViewDataColumn>
    </telerik:RadTreeListView.Columns>
     
</telerik:RadTreeListView>


Thanks.
Jose
0
Dimitrina
Telerik team
answered on 01 Nov 2011, 01:23 PM
Hi Jose,

 I am a little bit confused by this behavior. I have created a sample project following your instructions and the code snippets you have provided.

As you can see, at my end all the Nodes are populated fine. Could you please review my sample project and see what I have missed? Probbaly it is somehow different from your implementation.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jose
Top achievements
Rank 1
answered on 01 Nov 2011, 09:50 PM
I tried your project and you get the same thing I sent on the no-functions-binding.jpg from the original post. That is all nodes up to the source files, when the idea is that the files are also 'expandable' and their children are functions. From the view model you can see that for foo.cs you have 3 children (functions), Method001/Method002/Method003, similarly for bar.cs there is a child "AnotherMethod".

So the final hierarchy should be similar to the following:

Directory AAA
|__ SourceFile 001
                  |__ Function 001 <<=== function for sourcefile001, your project wouldnt show this
                  |__ Function 002  <<=== function for sourcefile001, your project wouldnt show this

|__ SourceFile 002
                  |__ Function 001 <<=== function for sourcefile002, your project wouldnt show this
                  |__ Function 002 <<=== function for sourcefile002, your project wouldnt show this

Directory BBB
|__ Directory BBB.1
                  |__ SourceFile 001
                                    |__ Function 001  

|__ SourceFile 002
                  |__ Function 001
                  |__ Function 002

The project you attached displays only up to the source files in that structure. That's why in my original code I had nested child definitions.

FYI, I'm using RadControls for WPF Q2 2011 SP1
Jose



0
Dimitrina
Telerik team
answered on 02 Nov 2011, 05:03 PM
Hello Jose,

 I apologize for my misunderstanding.

Unfortunately we do not support such a kind of nested child templates. You will need to have the same name for all the Children.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jose
Top achievements
Rank 1
answered on 02 Nov 2011, 07:23 PM
I see, thanks for following up Didie.
Tags
TreeListView
Asked by
Jose
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Jose
Top achievements
Rank 1
Share this question
or