Crash when using ItemTemplate

4 posts, 1 answers
  1. Bruno
    Bruno avatar
    54 posts
    Member since:
    Jul 2012

    Posted 05 May 2011 Link to this post

    Hello Telerik

    My silverlight App crashes when ever I use the ItemTemplate (since Update to Q1/2011 SP1.
    I need to do the template because my Tab-Header should contain two lines and an Image.

    My code (copy of http://www.telerik.com/help/silverlight/radtabcontrol-item-templates-and-selectors.html)

    <telerik:RadTabControl ItemsSource="{Binding TabItems, Mode=OneWay}" ItemTemplate="{StaticResource MainTabTemplate}" />

    and my MainTabTemplate looks as follows:
    <DataTemplate x:Key="MainTabTemplate">
       <Grid>
          <Grid.RowDefinitions>
             <RowDefinition />
             <RowDefinition />
          </Grid.RowDefinitions>
          <TextBlock Grid.Row="0"
                TextWrapping="Wrap"
                Text="FIRST LINE"/>
          <TextBlock Grid.Row="1"
                TextWrapping="Wrap"
                Text="{Binding Header}"/>
       </Grid>
    </DataTemplate>

    Now, when I try to start the app I get the following Error:

    A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.dll

    Additional information:  [Line: 0 Position: 0]


    What am I doing wrong?

    Thank you for your support!
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 05 May 2011 Link to this post

    Hello Bruno,

    I tested your scenario on our side but unfortunately I cannot reproduce the issue. Can you please have a look at the attached sample and let me know if it works for you or if I am missing something? Thank you in advance for your cooperation.

    Regards,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Bruno
    Bruno avatar
    54 posts
    Member since:
    Jul 2012

    Posted 06 May 2011 Link to this post

    Hello Tina

    Thank you for your working sample.
    The error can be reproduced also with your solution with the following steps:

    1. Change your ObservableCollection<DataItem> Tabs
    to ObservableCollection<RadTabItem> Tabs
    2. Change the Constructor of MyViewModel() to use RadTabItem instead of DataItem
    3. Recompile and try to start

    Why do I can't use RadTabItem to display the content of the TabControl?
    Thank you.
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 May 2011 Link to this post

    Hello Bruno,

    Thank you for the clarification. You can use RadTabItems but you cannot use the ItemTemplate and ContentTemplate properties in cases when the collection the TabControl is bound to contains visual elements. The ItemTemplate/ContentTemplate properties can only be applied to business items.

    Basically the ItemsSource property of the control is exposed to allow you to databind the control to a collection of business items, that have no visual representation. This is what the ItemTemplate and ContentTemplate properties do - define the visual presentation of business items.

    When you want to add RadTabItems you don't have to bind them, you can simply add them to the RadTabControl.Items collection.

    Please bear in mind that as in every ItemsControl, there are two expected ways to add items to the RadTabControl - by adding visual elements to the Items property or by setting the ItemsSource property to a data collection. In your case you are adding the items through the ItemsSource property but using a collection of visual elements, and although the RadTabControl supports this scenario, it isn't a good practice.

    I hope that info helps.

    Best wishes,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top