Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I use a custom TabItem control when databinding a TabControl in WPF?
    primarykey
    data
    text
    <p>I have a custom control that is derived from <code>TabItem</code>, and I want to databind that custom <code>TabItem</code> to a stock <code>TabControl</code>. I would rather avoid creating a new <code>TabControl</code> just for this rare case.</p> <p>This is what I have and I'm not having any luck getting the correct control to be loaded. In this case I want to use my <code>ClosableTabItem</code> control instead of the stock <code>TabItem</code> control.</p> <pre><code>&lt;TabControl x:Name="tabCases" IsSynchronizedWithCurrentItem="True" Controls:ClosableTabItem.TabClose="TabClosed" &gt; &lt;TabControl.ItemTemplate&gt; &lt;DataTemplate DataType="{x:Type Controls:ClosableTabItem}" &gt; &lt;TextBlock Text="{Binding Path=Id}" /&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><strong>EDIT:</strong> This is what I ended up with, rather than trying to bind a custom control. The "<a href="https://stackoverflow.com/questions/935043/how-can-i-get-a-close-button-on-a-templated-tabitem-in-wpf">CloseCommand</a>" im getting from a <a href="https://stackoverflow.com/questions/935043/how-can-i-get-a-close-button-on-a-templated-tabitem-in-wpf">previous question</a>.</p> <pre><code> &lt;Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}" &gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TabItem}"&gt; &lt;Border Name="Border" Background="LightGray" BorderBrush="Black" BorderThickness="1" CornerRadius="25,0,0,0" SnapsToDevicePixels="True"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="20,1,5,1"/&gt; &lt;Button Command="{Binding Path=CloseCommand}" Cursor="Hand" DockPanel.Dock="Right" Focusable="False" Margin="1,1,5,1" Background="Transparent" BorderThickness="0"&gt; &lt;Image Source="/Russound.Windows;component/Resources/Delete.png" Height="10" /&gt; &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="FontWeight" Value="Bold" /&gt; &lt;Setter TargetName="Border" Property="Background" Value="LightBlue" /&gt; &lt;Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" /&gt; &lt;Setter TargetName="Border" Property="BorderBrush" Value="DarkBlue" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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