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

Crash when using ItemTemplate

3 Answers 105 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 05 May 2011, 02:50 PM
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!

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 05 May 2011, 06:55 PM
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
0
Bruno
Top achievements
Rank 1
answered on 06 May 2011, 08:23 AM
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.
0
Accepted
Tina Stancheva
Telerik team
answered on 06 May 2011, 09:31 AM
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
Tags
TabControl
Asked by
Bruno
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Bruno
Top achievements
Rank 1
Share this question
or