Pseudo Classes
Pseudo classes are generated by a control, usually as a response to some sort of state.
For example :pointerover
pseudo class indicates that the pointer input is currently over (inside the bounds of) a control.
Pseudo classes are not set in the Classes
attributes of a control (unlike style classes).
Common pseudo classes include:
:focus
, :disabled
, :pressed
for buttons, and :checked
for checkboxes.
A control can have more than one pseudo class active at a time.
You can target one or more pseudo classes in a style selector. For example:
<Style Selector="Button.red:focus:pointover">
This selector targets button controls with the red class set, and that are in the :focus
and the :pointover
pseudo class state.
Some common pseudo classes:
Pseudo Class | Description |
---|---|
:pointerover | The pointer input is currently over (inside the bounds of) a control |
:focus | A control has the input focus. |
:disabled | A control is unable to respond to user interaction. |
:pressed | A button control is in the down position. |
:checked | A checkbox control is selected (check mark is showing). |
Custom Pseudo Classes
You can create your own pseudo classes for custom controls based on CustomControl
or TemplatedControl
. The function below adds or remove a pseudo class depending on a Boolean value on a StyledElement
.
PseudoClasses.Set(":className", bool);