Skip to main content

Microsoft Silverlight

Answered Question ContentTemplate for TabItem is not data binding properlyRSS Feed

(0)

UNSWITCH
UNSWITCH

Member

Member

0 points

3 Posts

ContentTemplate for TabItem is not data binding properly

I am using the Oct 2009 Silverlight Toolkit with SL3 and I have a strange problem with how the ContentTemplate properly is working for a TabItem. If the Content property of a TabItem is set using the attribute syntax method as follows, the ContentTemplate is applied as expected as shown in the following code:

<!-- Shows a single TabItem whose content contains a grid with yellow background and the text "This is a test". -->
<controls:TabControl>
  <controls:TabItem Header="Test1" Content="This is a test">
    <controls:TabItem.ContentTemplate>
      <DataTemplate>
        <Grid Background="Yellow">
          <ContentPresenter Content="{Binding}"/>
        </Grid>
      </DataTemplate>
    </controls:TabItem.ContentTemplate>
  </controls:TabItem>
</
controls:TabControl>

However, if the Content property of the TabItem is specified using element syntax, the ContentTemplate is applied, but the TabItems' Content is never data bound to the ContentPresenter inside of the ContentTemplate

<!-- Shows a single TabItem whose content contains a grid with yellow background but does NOT display the expected text (Content is missing). -->
<
controls:TabControl>
  <controls:TabItem Header="Test1">
    <controls:TabItem.Content>
      <TextBlock Text
="This is a test"/>
    </controls:TabItem.Content
>
    <controls:TabItem.ContentTemplate>
      <DataTemplate>
        <Grid Background="Yellow">
          <ContentPresenter Content="{Binding}"/>
        </Grid>
      </DataTemplate>
    </controls:TabItem.ContentTemplate>
  </controls:TabItem>
</
controls:TabControl>

Can anyone shed some light on why this problem happens? I don't understand why in the second code snippet, the Content is not displayed when the ContentTemplate is applied?

Thanks in advance!

 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP

Re: ContentTemplate for TabItem is not data binding properly

I think it might be a bug. or at least, it's inconsistent with WPF.

 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


UNSWITCH
UNSWITCH

Member

Member

0 points

3 Posts

Re: ContentTemplate for TabItem is not data binding properly

Some additional info...

This is causing me some major grief right now when trying to use the TabControl with Prism (Composite Application Library) and the TabControlRegionAdapter.

I was trying to modify the TabItem's ContentTemplate so I could wrap the view that gets added to the TabItem region with some additional Xaml that data binds to some properties on a View Model (sort of like how a HeaderTemplate can be used to data bind a TextBlock defined in the template to a property from the regions ViewModel).

However, when I created the ContentTemplate I could not get the ContentPresenter that is nested inside the DataTemplate to bind to the Content property and display the View. Thus, the view that gets added to the region is never displayed when a ContentTemplate is displayed. Only the XAML defined in the DataTemplate is displayed (which says to me the ContentTemplate is being applied, but databinding is not working).

I tried to simplify the problem by removing Prism from the picture and that's when I realized that what I am trying to do doesn't seem to work when using only the TabControl in SL3. It doesn't look like a Prism issue at the moment, but I'm relatively new to XAML so it's a bit of a struggle to trace this down.

Hope I explained that clearly...

Thanks!

Min-Hong Tang - MSFT
Min-Hong...

Contributor

Contributor

3619 points

412 Posts

Answered Question

Re: ContentTemplate for TabItem is not data binding properly

Hi Unswitch,

   Thank you for report this issue. We are aware of this issue now. And the develop team is working on it.

   So sorry for the inconvenience it brought you. If you need any help you can always come to us.

Best Regards

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

UNSWITCH
UNSWITCH

Member

Member

0 points

3 Posts

Re: Re: ContentTemplate for TabItem is not data binding properly

Excellent, thanks for the quick response! I'll keep an eye out for the fix.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities