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

ItemTemplateSelector

8 Answers 230 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 24 Apr 2009, 10:21 AM
Hi,

I'm just wondering if there is a way to use the Item TemplateSelector with a dynmic way to load the content template?

David

8 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 24 Apr 2009, 10:35 AM
Hello David,

In Silverlight 2 there is no way to define template in code. The only way is to define it in XAML and then reference is code or you can create some factory that will return valid XAML as string and you will parse it with XamlReader.Load method.
I hope that Silverlight 3 will have FrameworkElementFactory class like in WPF.

Let us know if you need more information.

Sincerely yours,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
David
Top achievements
Rank 1
answered on 24 Apr 2009, 12:06 PM
Hi thanks for the reply,

sorry should have said i know that but i was wondering i'll use the itemTemplateSelector to get the template i want but i need to load a diffrent ContentTemplate per Item any examples would be great as there arn't any in the examples program

David
0
Hristo
Telerik team
answered on 24 Apr 2009, 03:41 PM
Hi David,

You can find example on how to implement ItemTemplateSelector here:
http://demos.telerik.com/silverlight/#TreeView/HierarchicalTemplate

Let us know if you need more information.

Sincerely yours,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
David
Top achievements
Rank 1
answered on 27 Apr 2009, 11:22 AM
Hi i'm going to use a template selector so it need to be a ItemContainerStyleSelector but i can't find what i need to do for it could u do an example for me please

David
0
Miroslav
Telerik team
answered on 28 Apr 2009, 11:39 AM
Hello David,

Sorry if we cannot get to the problem quickly, but I may need some more information on what you are trying to achieve. I answered to a similar question here:

http://www.telerik.com/community/forums/silverlight/tabcontrol/setting-radtabitem-headertemplate-in-code-with-resource.aspx

There an ItemTemplateSelector is used. The DataTemplates for the selector are extracted from the ApplicationResources but you can get them from anywhere you like, for example  create them in code from a string.

Then, you can modify or create this string any way you like. For example you can still keep the DataTemplates in a .xaml file, then read them with an XMLReader (because Xaml is just XML) and modify or create them on the fly.

The ItemContainerStyleSelector works very similarly but instead of DataTemplates, you give styles. You just need to return a valid style, no matter how it is created or loaded.

I will advice to go for a StyleSelector only if you need to change the ControlTemplate or an external property for the containers and it is different for each of the containers. If you need to change the ContentTemplate or the HeaderTemplate, you can use the HeaderTemplateSelector and ItemTemplateSelector.

Here is a simple implementation of a StyleTemplateSelector:

public class MyStyleSelector : StyleSelector  
{  
    public override Style SelectStyle(object item, DependencyObject container)  
    {  
        if (item.GetType() == typeof(SomeType))  
        {  
            //Load it from string:  
            return XamlReader.Load(@"
                        <Style TargetType=""nav:RadTabItem""
                            xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""  
                            xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""  
                            xmlns:nav=""clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"">  
                            <Setter Property=""Background""  
                                    Value=""Red"" />  
                        </Style>") as Style;  
 
        }  
        else 
        {  
            //Or get it from resources:  
            return App.Current.Resources["DefaultCustomTabStyle"as Style;  
        }  
    }  
}  
 

Does this help you in your case? If you are thinking about something different, we may be able to help you with tips or advice.

Sincerely yours,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Calabonga
Top achievements
Rank 2
answered on 18 Jan 2010, 10:52 PM
I can't find any information about will SIlverlight 4 have FrameworkElementFactory.
Please answer me!
0
Tihomir Petkov
Telerik team
answered on 19 Jan 2010, 11:55 AM
Hello Sergei,

As far as I know, there will be no FrameworkElementFactory class in Silverlight 4.

Best wishes,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Calabonga
Top achievements
Rank 2
answered on 19 Jan 2010, 09:40 PM
ok...thanks...

I found that in a new Silverlight NET 4.0 poster (deepzoom)
new in NET 4.0
Tags
TabControl
Asked by
David
Top achievements
Rank 1
Answers by
Hristo
Telerik team
David
Top achievements
Rank 1
Miroslav
Telerik team
Calabonga
Top achievements
Rank 2
Tihomir Petkov
Telerik team
Share this question
or