Mediator
Mediator

Reputation: 15378

How add ControlTemplate to Content?

I have ControlTemplate (XAML). I need in code behid add ControlTemplate to TabItem.Content.

var tabItem = new TabItem
      {
      DataContext = listDesk,
      Header = headerText,
      Content = ???

      };

XAML

<ControlTemplate x:Key="MyTabItemContentTemplate" TargetType="controls:TabItem">
    <StackPanel>
        <TextBlock Text="wwwwww"/>
    </StackPanel>
</ControlTemplate>

I use SL4

Upvotes: 1

Views: 278

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178630

I think you're confusing concepts. Instead of setting the Content, which is data, set the Template, which is the visual representation of the control:

var tabItem = new TabItem
      {
      DataContext = listDesk,
      Header = headerText,
      Template = this.FindResource("MyTabitemContentTemplate") as ControlTemplate

      };

Moreover, chances are there is no reason to do this in code. You could be doing it entirely in XAML.

Upvotes: 3

Related Questions