BinaryRibbonBuiltInSkinController
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 | |
|---|---|
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. |
EffectiveAccentColor | Gets the accent colour the Fluent skins are drawing with now. |
IsWindowsInDarkMode | Gets whether Windows is set to dark mode for applications. |
OfficeBlack | Gets the resource dictionary of the RibbonSkin.OfficeBlack skin. |
OfficeBlue | Gets the resource dictionary of the RibbonSkin.OfficeBlue skin. |
OfficeSilver | Gets the resource dictionary of the RibbonSkin.OfficeSilver skin. |
Skin | Gets or sets the look of every ribbon in the application. |
Windows7 | Gets the resource dictionary of the RibbonSkin.Windows7 skin. |
| Methods | |
ContrastRatio | Works out the WCAG contrast ratio between two colours – how readable text in one is on the other. |
RefreshSystemAppearance | Applies the Windows appearance again if a skin that follows it is in force. |
| Events | |
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. |
Properties
AccentColor static
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
Gets the accent colour the Fluent skins are drawing with now.
- Value
AccentColorwhen the application has set one; otherwise the Windows accent; otherwise a Fluent blue.
IsWindowsInDarkMode static
Gets whether Windows is set to dark mode for applications.
- Value
truewhen the user has chosen dark for apps;falsewhen light, or when the setting cannot be read (Windows before 10).
OfficeBlack static
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
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
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
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
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
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
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
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.