This is a migrated thread and some comments may be shown as answers.

How to set ItemContainerStyle on dynamic items?

1 Answer 351 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 04 Nov 2008, 12:44 AM
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);
    }

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 06 Nov 2008, 04:33 PM
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.
Tags
General Discussions
Asked by
Sean
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or