Styling individual items in tree

3 posts, 1 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 13 Oct 2011 Link to this post

    Hi telerik,

    The users of our MVVM application would like items to be 'marked' in various ways; a combination of italics and bold is desired.

    Currently, we style the items as shown below, reacting to changes in IsSelected.

    The other thing we would like to react on is whether the treeitem's editor (in another window) is given focus, but of course there is no relevant RadTreeViewItem property to bind to - how would you go about this? Can we intercept the styling somehow and for each item - in code-as-opposed-to-markup - apply the style as we see fit?

    Thanks for any input,

    Anders, Denmark









    <Style TargetType="{x:Type Controls:RadTreeViewItem}">





    <Setter Property="WorkspaceExplorer:MouseDoubleClickBehavior.MouseDoubleClick" Value="{Binding ActivateItemCommand}" />





    <Setter Property="Margin" Value="0"/>





    <Setter Property="Padding" Value="0"/>





    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />





    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />





    <Setter Property="FontWeight" Value="Normal" />










    <Trigger Property="IsSelected" Value="True">





    <Setter Property="FontWeight" Value="Bold" />






















  2. Answer
    Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 18 Oct 2011 Link to this post

    Hi Anders,

    Basically at any time you can set the RadTreeViewItem.Style or the RadTreeView.ItemContainerStyle properties. And when the window for editing the item is opened you can apply a custom style to the RadTreeViewItem that is edited. Also, the RadTreeView control exposes also an ItemContainerStyleSelector property that gives you the ability to change the style for the RadTreeViewItems based on custom logic like a data property value, for example.

    I hope this info will help you implement your scenario. However, since I am not sure if I properly understand it, if I am missing something, please send us a sample code/solution demonstrating your requirements and scenario. Then we will be able to look further into it and find other approaches.

    All the best,
    Tina Stancheva
    the Telerik team

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

  3. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 05 Jan 2012 Link to this post

    Better late than never -- finally got back to this assignment -- and found your reply useful.

    Anders, Denmark.
Back to Top