Skip to content
Jean-Philippe Bruyère edited this page Nov 3, 2021 · 15 revisions

Styling allows you to define default properties values for all ui component as well as style class to quicky set the same value for a bunch of controls.

Syntax
StyleKey[, StyleKey...]{
    MemberName = "expression";
    ...;
}
example for all the Labels and the TextBox
Label, TextBox {
    Width = "Fit";
    Text = "Default Text";
}

You may also define custom style applicable to any widgets:

<Label Style="MyLabelStyle"/>

Then in the style file you set the property for your custom style:

MyLabelStyle {
    Width = "60";
    TextAlignment = "Right";
    Background = "DarkGrey";
}

Style names (widget or custom styles) are case sensitive. They may appear multiple times in different style files, and the defined properties for each will be combined. If a property is present multiple times for the same style name, only the first will be kept.

Any embeded resource with .style extension in the entry assembly will be loaded on startup, so you may override default style defined in the crow assembly easily.

After the entry assembly, the Interface has a static CrowAssemblyNames property which is a string array of simple assembly names to load at startup.

static void Main (string [] args) {
    Interface.CrowAssemblyNames = {"ControlLibrary"};
    using (VkChess app = new VkChess ())
        app.Run ();
}

All those assemblies will be scaned for style file prior the final loading of the crow assembly default.style

StyleKey may be any valid string not including ',' and '{' and white chars. Multiple StyleKeys are separated with a comma. Stylekey may be a widget class, or a custom id that will be used for the Style property of the widgets.

Example
CheckBox, RadioButton, StyleName1 {
    Focusable = "true";
    Height = "Fit";
    Background = "Red";
}

Member names may be any valid c# property name and expression could be any of the notations accepted in IML enclosed in "".

  • value type
  • binding
  • Event handler
  • Inline delegates

Expression must end with a ";".

Constants

Properties that are not inside brackets are replacement constants. They may be used once defined in any member value.

MyConstant = "Blue";
PressedColor = "Red";
Label {
    Foreground = "${MyConstant}";
    MouseDown = "{Foreground=${PressedColor}}";
}

The replacement string is done on xml parsing, so the constant may be anything inside the "". If a constant is defined multiple times, only the first one is kept.

Styling informations are concatenated for a particular class, and the style for a property appearing multiple times with different style key's targeting the same class will be chosen in the following order:

  1. Style property.
  2. fully qualified class name (including namespace).
  3. Simple class name.

Examples

You may define a generic style targeting the Label class in all namespaces, and define another style for a Label class in a particular namespace. In the following example, the second one will have priority for the Font member, but both backgrounds will be DimGray:

Label { Background = DimGray; Font = droid, 12; }
Crow.Label { Font = droid bold, 14; }

To make a new style for a bunch of labels sharing the same config, You may than add a Style attribute to your XML code, which will have priority on all other styling:

<Label Text="normal label"/>
<Label Style="BlueLabel" Text="this one will surely be blue"/>

Members

Valid members include public properties (having a Set accessor) and Events. Their are case sensitive.

Remark: Some properties (like Fit) store value in other properties (Fit => set Width and Height to Measure.Fit). It's a good idea to avoid using those kind of properties in style files, because their would override other styling properties even if their are redefined with a more specific style key: Imagine the default Label has the Fit property set to true in its default style, and you want a more specific style with fixed width to 150 for example, the Fit property style will reapply Measure.Fit value to Width and Height after having been set to 150 by the Width property style. So, to set the default sizing policy in a style, consider using Width=Fit;Height=Fit instead of Fit=true.

Expressions

For a complete example you may have a look to the default style of Crow.

Clone this wiki locally