Apply dynamic content changes after apply template

4 posts, 0 answers
  1. Adam
    Adam avatar
    70 posts
    Member since:
    Jun 2008

    Posted 19 Nov 2013 Link to this post


    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
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Nov 2013 Link to this post

    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 >>
  3. DevCraft banner
  4. Adam
    Adam avatar
    70 posts
    Member since:
    Jun 2008

    Posted 22 Nov 2013 Link to this post

    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.
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 26 Nov 2013 Link to this post

    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 >>
Back to Top