Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't want to set the <code>DataType</code> of the <code>DataTemplate</code> in this case. The value of the <code>ItemTemplate</code> property is used whenever a new item needs to be added, and in the case of a tab control it will be used to create a new <code>TabItem</code>. You should declare an instance of your class within the <code>DataTemplate</code> itself:</p> <pre><code>&lt;TabControl x:Name="tabCases" IsSynchronizedWithCurrentItem="True" Controls:ClosableTabItem.TabClose="TabClosed"&gt; &lt;TabControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Controls:ClosableTabItem&gt; &lt;TextBlock Text="{Binding Path=Id}" /&gt; &lt;/Controls:ClosableTabItem&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ItemTemplate&gt; &lt;TabControl.ContentTemplate&gt; &lt;DataTemplate DataType="{x:Type Entities:Case}"&gt; &lt;CallLog:CaseReadOnlyDisplay DataContext="{Binding}" /&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ContentTemplate&gt; &lt;/TabControl&gt; </code></pre> <p>This will cause a new <code>ClosableTabItem</code> to be created whenever a new tab is added to the <code>TabControl</code>.</p> <p><strong>Update</strong>; From your comment, it sounds like that the <code>ItemTemplate</code> controls what is created within the <code>TabItem</code>, rather than changing the <code>TabItem</code> itself. To do what you want to do, but for a <code>TreeView</code>, you would set the <code>HeaderTemplate</code>. Unfortunately, I don't see a <code>HeaderTemplate</code> property of <code>TabControl</code>.</p> <p>I did some searching, and <a href="http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out" rel="nofollow noreferrer">this tutorial</a> modifies the contents of the tab headers by adding controls to <code>TabItem.Header</code>. Maybe you could create a <code>Style</code> for your <code>TabItems</code> that would add the close button that your class is currently adding?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload