Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:26:05+00:00 2026-06-11T19:26:05+00:00

So in my main app ResourceDictionary I have a style that starts with <Style

  • 0

So in my main app ResourceDictionary I have a style that starts with

 <Style TargetType="{x:Type TabItem}" x:Key="{x:Type TabItem}">

Now what I’m doing is overriding the TabControl to make a custom control(without ANY xaml). The problem is at this point it doesn’t inherit the custom TabControl template.

So what I’m wondering, is how can I programatically bind to the ‘x:Key’ of the template, considering it’s bound to a specific control without having my control have a xaml file.

Some places online say to do this

this.Style = (Style)FindResource("TabItem");

But it doesn’t seem to work in my situation. The ‘style’ is in a separate file, and imported into my App.Xaml resource dictionary…so it overrides all TabItems properly, but not the one I overrode.

Here is my App.xaml

<Application x:Class="Octgn.OctgnApp" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>

        <ResourceDictionary Source="/Resources/Themes/Full/ExpressionDark.xaml"/>
       </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>

And the item(slightly truncated cause it’s large) from the ExpressionDark.xaml

<Style d:IsControlPart="True" TargetType="{x:Type TabItem}" x:Key="{x:Type TabItem}">
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Grid x:Name="grid" Margin="2,1,2,3">
                    <Grid.LayoutTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                            <SkewTransform AngleX="0" AngleY="0"/>
                            <RotateTransform Angle="0"/>
                            <TranslateTransform X="0" Y="0"/>
                        </TransformGroup>
                    </Grid.LayoutTransform>
                    <Border x:Name="border" BorderBrush="{x:Null}" CornerRadius="2,2,2,2" Opacity="0.5">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,0.976" StartPoint="0.5,0.039">
                                <GradientStop Color="#7F595959" Offset="0" />
                                <GradientStop Color="#19FFFFFF" Offset="1" />
                            </LinearGradientBrush>
                        </Border.Background>
                    </Border>
                    <Border x:Name="SelectedBorder" BorderBrush="{x:Null}" CornerRadius="2,2,2,2" Opacity="0" Background="{DynamicResource SelectedBackgroundBrush}"/>
                    <Border x:Name="HoverBorder" BorderBrush="{x:Null}" CornerRadius="2,2,2,2" Opacity="0">
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,0.976" StartPoint="0.5,0.039">
                                <GradientStop Color="#7F595959" Offset="0" />
                                <GradientStop Color="#19FFFFFF" Offset="1" />
                            </LinearGradientBrush>
                        </Border.Background>
                    </Border>
                    <Grid>
                        <ContentPresenter x:Name="ContentSite" RecognizesAccessKey="True" ContentSource="Header" d:LayoutOverrides="Width, Height" HorizontalAlignment="Center" Margin="6,1,6,1" VerticalAlignment="Center" />
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

This style auto applies to a TabItem, but I’m trying to apply it to my override of TabItem.

Here’s the code for that

/// <summary>
/// The chat bar item.
/// </summary>
public class ChatBarItem : TabItem
{
    /// <summary>
    /// Sets the Chat Room
    /// </summary>
    private readonly NewChatRoom room;

    /// <summary>
    /// Initializes static members of the <see cref="ChatBarItem"/> class.
    /// </summary>
    static ChatBarItem()
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(ChatBarItem), new FrameworkPropertyMetadata(typeof(TabItem)));
    }   

    /// <summary>
    /// Initializes a new instance of the <see cref="ChatBarItem"/> class.
    /// </summary>
    /// <param name="chatRoom">
    /// The chat Room.
    /// </param>
    public ChatBarItem(NewChatRoom chatRoom)
    {
        this.room = chatRoom;
        this.ConstructControl();
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="ChatBarItem"/> class.
    /// </summary>
    public ChatBarItem()
    {
        this.room = null;
        this.ConstructControl();
    }

    /// <summary>
    /// Constructs this control
    /// </summary>
    private void ConstructControl()
    {
        //this.Background = Brushes.Transparent;
        //this.BorderThickness = new Thickness(0);
        //this.Style = (Style)FindResource("TabItem");
        // this is where I want to set the style of this control

        // Main content object
        var mainBorder = new Border { Margin = new Thickness(5) };

        // Main content grid
        var g = new Grid();
        g.ColumnDefinitions.Add(new ColumnDefinition());
        g.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(16) });

        // Create item label
        var label = new TextBlock() { VerticalAlignment = VerticalAlignment.Center };
        if (this.IsInDesignMode() || this.room == null)
        {
            label.Inlines.Add(new Run("test"));
        }
        else
        {
            label.Inlines.Add(new Run(this.room.GroupUser.User.User));
        }

        // Create close button
        var borderClose = new Border { Width = 16, Height = 16 };
        var imageClose = new Image()
            {
                Source = new BitmapImage(new Uri("pack://application:,,,/Octgn;component/Resources/close.png")), 
                Stretch = Stretch.Uniform
            };

        // --Add items to items

        // Add close image to closeBorder
        borderClose.Child = imageClose;

        // Add Close 'button' to grid
        g.Children.Add(borderClose);
        Grid.SetColumn(borderClose, 1);

        // Add label to main grid
        g.Children.Add(label);

        // Add main grid to main border
        mainBorder.Child = g;

        // Add main grid to this
        this.Header = mainBorder;
    }
}

If I had a xaml for the TabItem I could easly just go Style=”{DynamicResource {x:Type TabItem}}”(or something similar), but I’m doing it all programatically.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:26:07+00:00Added an answer on June 11, 2026 at 7:26 pm

    You already tried:

    <Style TargetType="{x:Type TabControl}" BasedOn="{StaticResource {x:Type TabControl}}">
    
    </Style>
    

    By the way, you need not define an x:Key, if you want the style to be applied to all TabControl and if you want it to work for your entire application, set the style in App.xaml


    Edit: I still do not understand exactly what you want to do. (If you can, edit your question again).

    But you can try to set the style manually by:

    Style customStyle = (Style)Application.Current.FindResource("StyleKey");
    

    As mentioned,

    static MyCustomTabControl()
    {
         DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomTabControl), new FrameworkPropertyMetadata(typeof(TabControl)));
    } 
    

    But this will only work if:

    1) The style your control is in the file: Themes\Generic.xaml

    2) The file “Generic.xaml” has the property “BuildAction” with value = Page.

    3) AssemblyInfo.cs contains:

    [assembly: ThemeInfo (
         ResourceDictionaryLocation.None,
         ResourceDictionaryLocation.SourceAssembly
    )]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main app that will have many plugins. Here is the PluginReader
We have App A as main app. Now we build from it App B
I have a widget that is a part of my main app. Usually when
I have a widget that supposed to call an Activity of the main app
I have a main app that is able to call .net methods. My .net
Hello I have a main app that is going to have some plugins in
I have a splash screen that i want to run before my main app
I have a web application (MVC3) that is an Intranet, Main app. The solution
I have an app that consists of a main rails 3.2 app which acts
I've built myself a Rails Engine that requires that the main app have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.