WPF - override TabItem no longer auto sizes content

I

infectiouslogic

I have overridden TabItem for a new class ImageTabItem which throws an
image into the tab header. The header shows up fine, but the only
problem is when I add content to the ImageTabItem, it no longer will
supply the resizing that Auto will normally do. To summarize, I want
content with Width and Height of Auto to take up the whole content,
but it doesn't do that for the new ImageTabItem.
This is when I add a button the the ImageTabItem:

ImageTabItem tab = (ImageTabItem)tcScreens.SelectedItem;
ListForm list = new ListForm();
tab.Content = new Button();
....

all my Tabs are generated programmatically. For my ImageTabItem
class, I override the default style metadata in the static
constructor.
static ImageTabItem()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageTabItem), new
FrameworkPropertyMetadata(typeof(ImageTabItem)));
}

and in Generic.xaml, I set the style template, but you will see that
the template doesn't even mention Content at all, which is where I am
putting my controls that no longer auto size.

<Style TargetType="{x:Type local:ImageTabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type
local:ImageTabItem}">
<Grid Width="Auto" Height="Auto"
SnapsToDevicePixels="True">
<Border Margin="0,0,0,0" x:Name="Bd"
BorderBrush="#FF8E8C94" BorderThickness="1,1,1,0">
<Border.Background>
<LinearGradientBrush EndPoint="-0.02,0.998"
StartPoint="-0.02,0.229">
<GradientStop Color="#FFF3F3F3" Offset="0"/>
<GradientStop Color="#FFCDCDCD" Offset="1"/>
<GradientStop Color="#FFDDDDDD"
Offset="0.495"/>
</LinearGradientBrush>
</Border.Background>
<DockPanel x:Name="ContentPanel" Width="Auto"
Height="Auto" LastChildFill="False">
<ContentPresenter Width="Auto" Height="18"
DockPanel.Dock="Right" Margin="0,0,5,0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="Content" ContentSource="Header"/>
<Image Width="15" Height="15"
Source="/InfinID.UI.Win;component/images/office-building.png"
DockPanel.Dock="Left" Margin="5,0,0,0" SnapsToDevicePixels="True"
x:Name="PART_Image" />
</DockPanel>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background"
TargetName="Bd" Value="{StaticResource TabItemHotBackground}"/>
</Trigger>
<Setter Property="Background"
TargetName="Bd" Value="{StaticResource TabItemSelectedBackground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>

</Style>

When I disable the DefaultStyleKeyPropertyOverrideMetadata method call
below, the Auto sizing works again, so it must have to do with this
default style, but I just don't see where the Content fits into this.

Any takes on this?

Thanks!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top