HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonBuiltInSkinController

BinaryRibbonBuiltInSkinController

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.Office

Switches every ribbon in the application between the built-in looks – the Office 2007 and Windows 7 skins, ten colour skins and the Fluent skins of current Office – with one property.

public static partial class BinaryRibbonBuiltInSkinController

Remarks

Set Skin once at start-up, or whenever the user picks a look; every BinaryRibbonBarPanel, BinaryRibbonWindow and ribbon control in the application changes at once. It works by merging the chosen skin's resource dictionary into Resources (and taking the previous one out), so it needs a running Application.

Fluent skins

The Fluent skins (RibbonSkin.FluentWhite, RibbonSkin.FluentColorful, RibbonSkin.FluentDarkGray, RibbonSkin.FluentBlack and RibbonSkin.FluentSystem) take their accent from Windows unless AccentColor gives one, and are rebuilt when Windows reports a change of theme or accent (a BinaryRibbonWindow listens for that itself; elsewhere, call RefreshSystemAppearance). They are also put in force in the suite's skin manager, so other Binarymission controls that follow it match the ribbon. RibbonSkin.Shared works the other way round: the ribbon follows whatever skin the skin manager has.

Your own colours

Any key of BinaryRibbonThemeResources given a value directly in Resources wins over the skin, because the skin is a merged dictionary and WPF looks in a dictionary's own entries before its merged ones.

Examples

using System.Windows;
using System.Windows.Media;
using Binarymission.WPF.Controls.Office;

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        // The flat Office look, light or dark as Windows is, in the company's green.
        BinaryRibbonBuiltInSkinController.AccentColor = Color.FromRgb(0x10, 0x7C, 0x41);
        BinaryRibbonBuiltInSkinController.Skin = RibbonSkin.FluentSystem;

        // Redraw anything painted in code in the ribbon's colours when they change.
        BinaryRibbonBuiltInSkinController.SkinChanged += (sender, args) => RedrawStatusGlyphs();
    }
}

See also

Members at a glance

Properties
AccentColorGets or sets the accent colour the Fluent skins use for the application menu button, the selected tab and the other places Office puts its application colour.
EffectiveAccentColorGets the accent colour the Fluent skins are drawing with now.
IsWindowsInDarkModeGets whether Windows is set to dark mode for applications.
OfficeBlackGets the resource dictionary of the RibbonSkin.OfficeBlack skin.
OfficeBlueGets the resource dictionary of the RibbonSkin.OfficeBlue skin.
OfficeSilverGets the resource dictionary of the RibbonSkin.OfficeSilver skin.
SkinGets or sets the look of every ribbon in the application.
Windows7Gets the resource dictionary of the RibbonSkin.Windows7 skin.
Methods
ContrastRatioWorks out the WCAG contrast ratio between two colours – how readable text in one is on the other.
RefreshSystemAppearanceApplies the Windows appearance again if a skin that follows it is in force.
Events
SkinChangedOccurs after a skin has been applied – when Skin is set, when a Fluent skin is rebuilt because the accent colour or the Windows light or dark setting changed, and when RibbonSkin.Shared follows a new skin in the skin manager.

Properties

AccentColor static

public static Color? AccentColor

Gets or sets the accent colour the Fluent skins use for the application menu button, the selected tab and the other places Office puts its application colour.

Value
The accent, or null – the default – to take the one the user chose in Windows.
Remarks

Setting it while a Fluent skin is in force applies it at once. Text drawn in the accent is darkened or lightened as far as it needs to be to stay readable on the theme's surfaces, so any colour can be given here.

EffectiveAccentColor static

public static Color EffectiveAccentColor

Gets the accent colour the Fluent skins are drawing with now.

Value
AccentColor when the application has set one; otherwise the Windows accent; otherwise a Fluent blue.

IsWindowsInDarkMode static

public static bool IsWindowsInDarkMode

Gets whether Windows is set to dark mode for applications.

Value
true when the user has chosen dark for apps; false when light, or when the setting cannot be read (Windows before 10).

OfficeBlack static

public static ResourceDictionary OfficeBlack

Gets the resource dictionary of the RibbonSkin.OfficeBlack skin.

Value
The same dictionary every time; it is created on first use.
Remarks

Set Skin to apply a skin. Read this to look up one of the skin's resources, or to merge the skin into a dictionary of your own.

OfficeBlue static

public static ResourceDictionary OfficeBlue

Gets the resource dictionary of the RibbonSkin.OfficeBlue skin.

Value
The same dictionary every time; it is created on first use.
Remarks

Set Skin to apply a skin. Read this to look up one of the skin's resources, or to merge the skin into a dictionary of your own.

OfficeSilver static

public static ResourceDictionary OfficeSilver

Gets the resource dictionary of the RibbonSkin.OfficeSilver skin.

Value
The same dictionary every time; it is created on first use.
Remarks

Set Skin to apply a skin. Read this to look up one of the skin's resources, or to merge the skin into a dictionary of your own.

Skin static

public static RibbonSkin Skin

Gets or sets the look of every ribbon in the application.

Value
The skin. The starting value is RibbonSkin.Custom, which applies no built-in skin.
Remarks

Setting a new value takes the old skin's dictionaries out of the application's resources, puts the new one's in, and raises SkinChanged. Setting the value already in force does nothing.

It needs Current: setting it before the Application object exists throws a NullReferenceException.

Example
// Let the user choose a look from a menu of RibbonSkin values.
private void OnSkinChosen(object sender, RoutedEventArgs e)
{
    BinaryRibbonBuiltInSkinController.Skin = (RibbonSkin)((MenuItem)sender).Tag;
}

Windows7 static

public static ResourceDictionary Windows7

Gets the resource dictionary of the RibbonSkin.Windows7 skin.

Value
The same dictionary every time; it is created on first use.
Remarks

Set Skin to apply a skin. Read this to look up one of the skin's resources, or to merge the skin into a dictionary of your own.

Methods

ContrastRatio static

public static double ContrastRatio(Color a, Color b)

Works out the WCAG contrast ratio between two colours – how readable text in one is on the other.

Parameters
a
One colour.
b
The other; the order does not matter.
Returns

The ratio, from 1 (no contrast) to 21 (black on white). WCAG asks for at least 4.5 for ordinary text and 3 for large text.

Example
// Pick white or black text for a swatch of the user's accent colour.
Color accent = BinaryRibbonBuiltInSkinController.EffectiveAccentColor;
Color text = BinaryRibbonBuiltInSkinController.ContrastRatio(accent, Colors.White) >= 4.5
    ? Colors.White
    : Colors.Black;

RefreshSystemAppearance static

public static void RefreshSystemAppearance()

Applies the Windows appearance again if a skin that follows it is in force.

Remarks

BinaryRibbonWindow calls this itself when Windows reports that the theme or the accent has changed. An application whose ribbon is not in one calls it from its own handling of WM_SETTINGCHANGE.

Events

SkinChanged static

public static event EventHandler SkinChanged

Occurs after a skin has been applied – when Skin is set, when a Fluent skin is rebuilt because the accent colour or the Windows light or dark setting changed, and when RibbonSkin.Shared follows a new skin in the skin manager.

Remarks

For an application that draws pictures of its own in the ribbon's colours – a glyph drawn in code, say – and has to draw them again when those colours change.