开发者

Change Layout (Template) in runtime build controls

My scenario:

I have in my form a tabControl. I've extended the TabItem control to some other classes that I want to add the TabControl.

I need that each one of the ExtendedTabItem have a speci开发者_开发技巧fic header and data template.

Something in the line of:

<DataTemplate DataType="ExtendedTabItem">
   <StackPanel Height="100" Width="90">
      <TextBlock Text="{Binding Path=Referencia}" FontSize="13" 
         HorizontalAlignment="Center" Margin="0,0,0,1" />
      <TextBlock Text="{Binding Path=Estado}" FontSize="9" 
         HorizontalAlignment="Center" Margin="0,0,0,1" />
   </StackPanel>
</DataTemplate>

And then I could simply


Class ExtendedTabItem : TabItem {
    // bla bla bla
}

Action()
{
   ExtendedTabItem A = new ExtendedTabItem();
   A.Header = SelectedItem.Referencia;
   tabControl1.Items.Add(A);
}

Is this doable? All my searches seem to point to the use of an DatTemplateSelector but it does not seem quite what I need.


I was able to work around by defining the Template at run time.

<DataTemplate x:Key="t1" DataType="l:CloseableTabItem">

A.ContentTemplate = this.FindResource("t1") as DataTemplate;

I' would still prefer a solution that would not need that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜