ItemTemplateSelector

9 posts, 0 answers
  1. David
    David avatar
    21 posts
    Member since:
    Apr 2009

    Posted 24 Apr 2009 Link to this post

    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
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 24 Apr 2009 Link to this post

    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.
  3. DevCraft banner
  4. David
    David avatar
    21 posts
    Member since:
    Apr 2009

    Posted 24 Apr 2009 Link to this post

    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
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 24 Apr 2009 Link to this post

    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.
  6. David
    David avatar
    21 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    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
  7. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 28 Apr 2009 Link to this post

    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.
  8. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 18 Jan 2010 Link to this post

    I can't find any information about will SIlverlight 4 have FrameworkElementFactory.
    Please answer me!
  9. Tihomir Petkov
    Admin
    Tihomir Petkov avatar
    576 posts

    Posted 19 Jan 2010 Link to this post

    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.
  10. Calabonga
    Calabonga avatar
    29 posts
    Member since:
    Nov 2009

    Posted 19 Jan 2010 Link to this post

    ok...thanks...

    I found that in a new Silverlight NET 4.0 poster (deepzoom)
    new in NET 4.0
Back to Top
DevCraft banner