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

Apply dynamic content changes after apply template

3 Answers 48 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 19 Nov 2013, 08:47 PM

Hi there,

I'm working with the RadTreeView and have HierarchicalDataTemplates defined. Part of our application's requirements involves some dynamic configuration of things like visibility, size, etc. for controls within the RadTreeViewItem. Currently, I've attempted to make those settings in the OnItemPrepared, but it appears that the item is not actually "prepared" in the sense that it is done rendering here; the item has no visual children. If I explicitly call ApplyTemplate, then I can access the controls. However, I'm afraid that calling this explicitly may impact other features like virtualization or mess up the overall lifecycle of the treeview.

So, is there a better way to handle a scenario like this? 

Thanks!
Adam.g

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 22 Nov 2013, 12:21 PM
Hi Adam,

The usual way to control these settings is with using Styles for RadTreeViewItems. If you need to add logic for some of the RadTreeViewItems' properties you can add corresponding properties in your ViewModels and bind these properties with Styles, for example:
<Style x:Key="ItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
    <Setter Property="IsSelected" Value="{Binding Path=Selected}"/>
    <Setter Property="IsExpanded" Value="{Binding Path=Expanded}"/>
</Style>
This is also demonstrated in the following help article (the code for it works in SL 5 too).

Please let us know if you need further assitance on this.

Regards,
Petar Mladenov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Adam
Top achievements
Rank 1
answered on 22 Nov 2013, 12:37 PM
Yes, thank you, I am aware of that. And for our default layouts we already use templates and styles. However, again, the settings we need to apply are completely dynamic. Additionally, they encompass other settings that wouldn't normally be done through styles or binding anyway. For instance, we may be filtering out certain items from combo boxes after they are bound to an initial collection.
0
Petar Mladenov
Telerik team
answered on 26 Nov 2013, 10:00 AM
Hi Adam,

I believe that every requirement for changing some properties of the controls in the RadTreeViewItems can be achieved by using ViewModels and if these controls are located  the ItemTemplate of the TreeViewItems. Could you please elaborate more on the thing that these settings are *completely dynamic* ? If the templates and ViewModels are properly configured I think your requirement is easy to achieve.
However, if you hit an issue related to the fact that the TreeViewItem is not completely prepared in the ItemPrepared event, probably you can wrap the logic in the ItemPrepared event handler in Dispatcher.BeginInvoke() body. 

Regards,
Petar Mladenov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
TreeView
Asked by
Adam
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Adam
Top achievements
Rank 1
Share this question
or