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 = ???

            CurrentTreeViewItem.Items.Add(item);
        }
  2. Hristo
    Admin
    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="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            x:Class="Telerik.Windows.Examples.App">  
        <Application.Resources> 
            <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" /> 
            </Style> 
        </Application.Resources> 
    </Application> 

    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,
    Hristo
    the Telerik team

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