Tabs Studio Blog (organizing Visual Studio document tabs)

November 18, 2010

Updating a style from add-ins

Filed under: Uncategorized — Tags: , — Sergey Vlasov @ 11:09 am

Continuing work on reducing necessity to manually craft a XAML style, I’ve added the ability to update a style from an add-in. For example, previously for SingleRow and Shaper add-ins you needed to copy sample styles from documentation and to use them together you needed to merge these styles. Newly updated SingleRow and Shaper programmatically apply default styles not cluttering the custom style:

Default SingleRow and Shaper styles

Default SingleRow and Shaper styles

The only thing missing from the sample Chrome style for Shaper is the grey line under the tabs, as currently only setters and triggers can be automatically merged, not control templates. To make it perfect, the following custom style can be used:

<Style TargetType="TabsStudio:TabsHost" BasedOn="{StaticResource DefaultTabsHostStyle}">
  <Setter Property="Template">
      <ControlTemplate TargetType="{x:Type TabsStudio:TabsHost}">
        <Grid Panel.ZIndex="1">
          <Rectangle Width="{TemplateBinding Width}"
                     Height="{TemplateBinding Height}"
                     Fill="{TemplateBinding Background}"/>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            <ContentPresenter Grid.Column="0"/>
            <TabsStudioSingleRow:HiddenTabs Grid.Column="1" TabsPanel="{TemplateBinding ContentControl.Content}"/>
      <Border Height="1" Background="#93979D"/>
The manually merged TabsHost style for SingleRow and Shaper

The manually merged TabsHost style for SingleRow and Shaper

Internally, the void UpdatePresentationStyles(string key, Presentation presentation) method was added to the TabsStudioExt.ITabsStudioEngine interface. It is possible to update styles dynamically, but right now SingleRow and Shaper do it only once in the OnConnection handler.

Triggers and setters for default Tabs Studio controls are added to the Styles property. For new controls (like TabsStudioSingleRow:HiddenTabs) a style resource and a default style usage are provided in the Presentation constructor:

private void UpdatePresentationStyle()
    TabsStudioExt.Presentation presentation = new TabsStudioExt.Presentation(
        LoadString("HiddenTabsStyle.xml"), LoadString("HiddenTabsUsage.xml"));
        TabsStudioExt.PresentationStyle style = new TabsStudioExt.PresentationStyle();
        presentation.Styles.Add("TabsStudio:Tab", style);
        TabsStudioExt.PresentationStyle style = new TabsStudioExt.PresentationStyle();
        presentation.Styles.Add("TabsStudio:TabsHost", style);
    engine.UpdatePresentationStyles("SingleRow", presentation);

The style parameter in the Presentation constructor can also add static resources for use in tab coloring rules. Theoretically it may be a custom brush or a generated color. These changes are included in the upcoming Tabs Studio release.

Blog at

%d bloggers like this: