ItemContainerStyle with static items

3 posts, 1 answers
  1. IT-Support
    IT-Support avatar
    9 posts
    Member since:
    Dec 2011

    Posted 21 Jun 2015 Link to this post

    Hi,

    I use the RadTreeView with static items - RadTreeViewItems are created in code. I need the tree items to stretch horizontally - so I set the ItemContainerStyle:

    <telerik:RadTreeView.ItemContainerStyle>            
       <Style TargetType="telerik:RadTreeViewItem">
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Padding" Value="0" />
        </Style>
    </telerik:RadTreeView.ItemContainerStyle>

    Unfortunately the style is applied only the root items - like stated in the documentation:

    • "When using ItemContainerStyle with static items, it will get applied only to the direct children of the RadTreeView - the top-level items. If you want their child items to have the same style you have to manually set the ItemContainerStyle property of their parents." (Documentation)

    I do not understand how to "manually set the ItemContainerStyle property of their parents". Is there a working example how to use ItemContainerStyle with static items?

    Beste regards,
    Thomas

  2. Answer
    Milena
    Admin
    Milena avatar
    204 posts

    Posted 22 Jun 2015 Link to this post

    Hi Thomas,

    Thank you for the detailed explanation.

    Indeed, if you set ItemContainerStyle  to the TreeView as an ItemsControl this style will get applied to the root items only (direct children), but not to the nested items. However, I could suggest you using implicit style to the RadTreeViewItem: 
    <Style TargetType="telerik:RadTreeViewItem" >
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="Padding" Value="0" />
    </Style>

    I hope this helps.

    Regards,
    Milena
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. IT-Support
    IT-Support avatar
    9 posts
    Member since:
    Dec 2011

    Posted 22 Jun 2015 in reply to Milena Link to this post

    Hi Milena,

    works as intended - thank you very much!

    Best regards,
    Thomas

Back to Top