How to set ItemContainerStyle on dynamic items?

2 posts, 0 answers
  1. Sean
    Sean avatar
    2 posts
    Member since:
    Nov 2008

    Posted 03 Nov 2008 Link to this post

    I'm attempting to recreate the Lookless tree view demo with dynamic items, and I'm having difficulty setting the ItemContainerSytle for new items- any idea?

    RadTreeViewItem item;
        foreach (ServiceReference1.DataResult y in x) {
            item = new RadTreeViewItem();
            item.Header = y.Name
            item.ItemContainerStyle = ???

  2. Hristo
    Hristo avatar
    832 posts

    Posted 06 Nov 2008 Link to this post

    Hello Sean,

    The recommended way is to create your Style in XAML (probably using Expression Blend 2 SP1) and get the reference to it. If you put your Style in App.xaml resources you can set the x:Key attribute on the Style like this:

    <Application xmlns="" 
            <Style x:Key="PropertyGridOuterBorder" TargetType="Border">  
                <Setter Property="MinWidth" Value="250" /> 
                <Setter Property="HorizontalAlignment" Value="Right" /> 
                <Setter Property="BorderBrush" Value="#19000000" /> 
                <Setter Property="BorderThickness" Value="1,0,0,0" /> 

    and you can get the reference in code using this syntax:

    Style borderStyle = Application.Current.Resources["PropertyGridOuterBorder"as Style; 

    Note that I am using the same key in code and in XAML or you will get null instead.
    If you have other questions, do not hesitate to contact us.

    Sincerely yours,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top