BinarySkin
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 | |
|---|---|
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. |
CornerRadius | Gets or sets how far the corners of buttons, menus and panels are rounded. |
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. |
Item | Gets or sets one of the skin's colours. |
Name | Gets or sets the name shown for the skin – in a skin picker, say, and in a skin file. |
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. |
Roles | Gets every colour a skin has, in the order a skin file lists them. |
| Methods | |
Clone | Makes an independent copy, to change without changing this one. |
CreateBrush | Creates a frozen brush in one of the skin's colours. |
CreateBrush | Creates a frozen brush in a colour – for a control making colours of its own from a skin's. |
LooksTheSameAs | Determines whether another skin draws exactly as this one does: the same colours, rounding and effects. |
ToString | Returns the skin's name. |
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. |
| Fields | |
MaximumCornerRadius | The largest corner rounding a skin may ask for: 12 device-independent units (1/96 inch). |
Properties
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 withnew, when it was made from nothing.BinarySkins.Create()sets it.
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
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
truefor a dark skin. The default isfalse; the built-inDarkGrayandBlackskins set it.
Item
Gets or sets one of the skin's colours.
- Value
- The colour, alpha included. A skin made with
newhas every colour transparent until it is set.
Parameters
role- Where the colour is used.
Exceptions
ArgumentOutOfRangeExceptionroleis not a colour a skin has.
Example
skin[BinarySkinColor.Accent] = Color.FromRgb(0xC2, 0x41, 0x0C);
Color text = skin[BinarySkinColor.SurfaceText];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
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-inColorfulskin sets it tofalse, since the backdrop would hide its accent-coloured canvas.
Roles static
Gets every colour a skin has, in the order a skin file lists them.
- Value
- A read-only list of every
BinarySkinColorvalue.
Methods
Clone
Makes an independent copy, to change without changing this one.
Returns
A new skin with the same name, colours, rounding and effects.
CreateBrush
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
ArgumentOutOfRangeExceptionroleis not a colour a skin has.
CreateBrush static
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
Determines whether another skin draws exactly as this one does: the same colours, rounding and effects.
Parameters
other- The other skin;
nullgivesfalse.
Returns
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
The largest corner rounding a skin may ask for: 12 device-independent units (1/96 inch).