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

Accessing Additional Templated Controls in RadTreeViewItem

4 Answers 65 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 14 Nov 2014, 07:41 PM
I'm using a ControlTemplate to add a couple of additional Controls (an Image and a TextBlock) to RadTreeViewItem. I'm also using a HierarchicalDataTemplate and data binding to attach the RadTreeView to my data.

With this, I'm unable to find any way to bind these additional controls to data, or access the additional controls in code. If I were creating the TreeViewItems myself, I think I'd create a subclass of RadTreeViewItem and add a couple of properties that I could bind the new controls to.

What I ended up doing was add the following to RadTreeViewItem:
/// <summary>
/// Exposes protected GetTemplateChild
/// </summary>
public DependencyObject PublicGetTemplateChild(string childName)
{
    //
    //  In the base control class GetTemplateChild is protected. I need to open it up for
    //  RadTreeViewItem so we can find elements that we added in data templates
    //
    return GetTemplateChild(childName);
}

This allows me to find my child controls in code when the RadTreeViewItem is loaded and then bind my data to them.

Is there a better way to do this?

Is it possible to get the RadTreeView to create my sub-classed RadTreeViewItem, rather than a RadTreeViewItem? It looks like it isn't, but if there's no better way to do this, would it be worth adding?


4 Answers, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 19 Nov 2014, 09:51 AM
Hello Mark,

Do you mind sharing with us why you need to customize the ControlTemplpate of the RadTreeViewItem to achieve your requirement? Is it not possible to create custom DataTempalte and assign it to the RadTreeViewItem.ItemTemplate? Please keep in mind that if our customers change the default ControlTemplates of our controls we will no longer support those changes. This is why it would better to use custom DataTemplate instead of changing the ControlTemplate.

Working with custom DataTemplate allows you to use bindings. This way you will be able to control the additional UI components through your business items. At this point  I cannot see any benefits in customizing the default ControlTempalte of the RadTreeViewItem in your particular scenario.

Basically, you can define the same visual structure with a DataTemplate. Could you please send me a picture of the result that you need to achieve and I will try to create a DataTemplate achieving your requirement for you? 

Regards,
Pavel R. Pavlov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark
Top achievements
Rank 1
answered on 19 Nov 2014, 05:34 PM
Pavel,

Thanks for the reply. 

>>Is it not possible to create custom DataTempalte and assign it to the RadTreeViewItem.ItemTemplate?
That's what I was hoping to hear (or at least something like it). It seemed I was going about this the wrong way. All the examples I saw for DataTemplate/ItemTemplate seemed to be binding data to the existing TreeViewItem layout. Looking closer at http://www.telerik.com/help/silverlight/radtreeview-populating-with-data-item-template.html, I see that the controls are being defined directly in the DataTemplate, they just happen to look like a normal TreeViewItem.

I don't know how I got off on the ControlTemplpate tangent, I think I found some samples that used it to change the appearcne of the treeview and it wasn't apparent to me that the DataTemplate/ItemTemplate contains controls.

I'll give it another shot.

Attached is a first stab at what I'm trying to accomplish. Several images bound to different properties (fileType,dirtyFlag and versionStatus), and 2 blocks of text bound to different proprties (name and status). All 1-way bindings. The tree isn't editable.
0
Accepted
Petar Mladenov
Telerik team
answered on 24 Nov 2014, 01:10 PM
Hello Mark,

The following samples and help articles also demonstrate custom DataTemplates used for ItemTemplate of the RadTreeView. Please let us know if you need further assistance.

RadTreeView How to Implement Tri State CheckBox with MVVM
RadTreeView First Look Demo 
RadTreeView HierarchicalDataTemplate Demo

Regards,
Petar Mladenov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark
Top achievements
Rank 1
answered on 24 Nov 2014, 03:08 PM
The tri-state example is it exactly. I don't know how I missed it. Thanks.
Tags
TreeView
Asked by
Mark
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Mark
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or