HypernovaDesktop Components · docs
Binarymission
WPF › Skinning › BinarySkin

BinarySkin

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Skinning

A skin: the colours the Binarymission controls are drawn in, each named for the place it is used, with the corner rounding and window effects that go with them.

public sealed class BinarySkin

Remarks

Making a skin

Start from a built-in skin with BinarySkins.Create(), change what should differ – a colour through the indexer, CornerRadius, Name – and put it in force with BinarySkinManager.Apply. A skin can also be read from a file with BinarySkinSerializer.Load(). A skin made with new BinarySkin() starts with every colour transparent, so a built-in one is the better start.

Colours by role

Each colour is a BinarySkinColor – "the text on a surface", "a command under the pointer" – rather than a hue, so a control asks for the role and gets whatever the skin in force says it is. Roles lists them all.

Checking it

Validate reports any text that would be hard to read and any change of state a user could not see, measured as the Web Content Accessibility Guidelines measure contrast, so a skin can be checked before it ships.

A skin is a plain object: changing one changes nothing on screen until it is applied. The skin manager keeps its own copy.

Examples

A teal skin made from the built-in light one, checked, put in force and saved for later.

using System.Diagnostics;
using System.Windows.Media;
using Binarymission.WPF.Skinning;

BinarySkin skin = BinarySkins.Create(BinarySkinTheme.White, Color.FromRgb(0x2B, 0xA3, 0xA3));
skin.Name = "Harbour";
skin[BinarySkinColor.Surface] = Color.FromRgb(0xF4, 0xF8, 0xF8);
skin.CornerRadius = 6;

foreach (BinarySkinProblem problem in skin.Validate())
{
    Debug.WriteLine(problem.Description);
}

BinarySkinManager.Apply(skin);
BinarySkinSerializer.Save(skin, "Harbour.skin.json");

See also

Members at a glance

Properties
BasedOnGets or sets the built-in skin this one was made from, which a skin file records so that it can be read back the same way.
CornerRadiusGets or sets how far the corners of buttons, menus and panels are rounded.
IsDarkGets or sets whether the skin is a dark one, so that Windows draws the window frame and backdrop dark to match, and controls that follow the skin can choose their own dark variants.
ItemGets or sets one of the skin's colours.
NameGets or sets the name shown for the skin – in a skin picker, say, and in a skin file.
PrefersSystemBackdropGets or sets whether a window that can show the Windows backdrop (Mica, on Windows 11) behind its title should do so rather than fill it with BinarySkinColor.Canvas.
RolesGets every colour a skin has, in the order a skin file lists them.
Methods
CloneMakes an independent copy, to change without changing this one.
CreateBrushCreates a frozen brush in one of the skin's colours.
CreateBrushCreates a frozen brush in a colour – for a control making colours of its own from a skin's.
LooksTheSameAsDetermines whether another skin draws exactly as this one does: the same colours, rounding and effects.
ToStringReturns the skin's name.
ValidateChecks that every piece of text in the skin reads on what it is drawn on, and that a user can see a command change under the pointer and when pressed.
Fields
MaximumCornerRadiusThe largest corner rounding a skin may ask for: 12 device-independent units (1/96 inch).

Properties

BasedOn

public BinarySkinTheme? BasedOn

Gets or sets the built-in skin this one was made from, which a skin file records so that it can be read back the same way.

Value
The built-in skin; null, the default for a skin made with new, when it was made from nothing. BinarySkins.Create() sets it.

CornerRadius

public double CornerRadius

Gets or sets how far the corners of buttons, menus and panels are rounded.

Value
In device-independent units (1/96 inch), from 0 (square) to MaximumCornerRadius; the default is 4.
Exceptions
ArgumentOutOfRangeException
The value is outside that range, or not a number.

IsDark

public bool IsDark

Gets or sets whether the skin is a dark one, so that Windows draws the window frame and backdrop dark to match, and controls that follow the skin can choose their own dark variants.

Value
true for a dark skin. The default is false; the built-in DarkGray and Black skins set it.

Item

public Color this[BinarySkinColor role]

Gets or sets one of the skin's colours.

Value
The colour, alpha included. A skin made with new has every colour transparent until it is set.
Parameters
role
Where the colour is used.
Exceptions
ArgumentOutOfRangeException
role is not a colour a skin has.
Example
skin[BinarySkinColor.Accent] = Color.FromRgb(0xC2, 0x41, 0x0C);
Color text = skin[BinarySkinColor.SurfaceText];

Name

public string Name

Gets or sets the name shown for the skin – in a skin picker, say, and in a skin file.

Value
The name, with surrounding white space removed. Never empty; the default is "Untitled".
Exceptions
ArgumentException
The value is null, empty or white space.

PrefersSystemBackdrop

public bool PrefersSystemBackdrop

Gets or sets whether a window that can show the Windows backdrop (Mica, on Windows 11) behind its title should do so rather than fill it with BinarySkinColor.Canvas.

Value
true, the default, to let the backdrop show. The built-in Colorful skin sets it to false, since the backdrop would hide its accent-coloured canvas.

Roles static

public static IList<BinarySkinColor> Roles

Gets every colour a skin has, in the order a skin file lists them.

Value
A read-only list of every BinarySkinColor value.

Methods

Clone

public BinarySkin Clone()

Makes an independent copy, to change without changing this one.

Returns

A new skin with the same name, colours, rounding and effects.

CreateBrush

public SolidColorBrush CreateBrush(BinarySkinColor role)

Creates a frozen brush in one of the skin's colours.

Parameters
role
The colour.
Returns

A new, frozen SolidColorBrush, safe to share between threads and controls.

Exceptions
ArgumentOutOfRangeException
role is not a colour a skin has.

CreateBrush static

public static SolidColorBrush CreateBrush(Color color)

Creates a frozen brush in a colour – for a control making colours of its own from a skin's.

Parameters
color
The colour.
Returns

A new, frozen SolidColorBrush.

LooksTheSameAs

public bool LooksTheSameAs(BinarySkin other)

Determines whether another skin draws exactly as this one does: the same colours, rounding and effects.

Parameters
other
The other skin; null gives false.
Returns

true when nothing a user could see differs. Name and BasedOn are not compared.

ToString

public override string ToString()

Returns the skin's name.

Returns

Validate

public IList<BinarySkinProblem> Validate()

Checks that every piece of text in the skin reads on what it is drawn on, and that a user can see a command change under the pointer and when pressed.

Returns

One BinarySkinProblem for each pair of colours that is too alike; an empty list when nothing is wrong.

Remarks

Text must reach ColorContrast.TextRatio (4.5) on what it is drawn on, the selected tab's underline ColorContrast.GraphicRatio (3), and a pointer or pressed colour BinarySkinProblem.StateChangeRatio (1.1) against the colour it replaces. Nothing is changed; the problems are only reported.

Fields

MaximumCornerRadius

public const double MaximumCornerRadius

The largest corner rounding a skin may ask for: 12 device-independent units (1/96 inch).