A BAML record never holds a type name or a property name: it holds a number. This page tells what the number points at and how the compact values of PropertyCustom are written. The sources are the same as for the records, plus WPF’s Baml2006KnownTypes.cs, SolidColorBrush.cs, ParserStreamGeometryContext.cs, XamlSerializationHelper.cs, XamlInt32CollectionSerializer.cs and Knowncolors.cs.
Ids
| Kind of id | 0 or more | Below 0 |
|---|---|---|
| Type id | an entry of the file’s TypeInfo records | a type built into the reader: the id with its sign dropped is a position from 1 in a list of 759 WPF types and CLR types |
| Property id | an entry of the file’s AttributeInfo records | a property built into the reader: 268 entries from 1 (137 is unused), each a property of a WPF type |
| String id | an entry of the file’s StringInfo records | -1 is Name and -2 is Uid |
| Assembly id | an entry of the file’s AssemblyInfo records (0 to 4095: the top four bits of the field in TypeInfo are flags) | -1 System, -2 WindowsBase, -3 PresentationCore, -4 PresentationFramework |
| Converter and serializer type id | in PropertyCustom the id is positive and is a position in the built-in type list (the serializers are in it) | in PropertyWithConverter and TextWithConverter a built-in converter is a negative type id |
A built-in type is named without a namespace by the reader: Button, Boolean, BooleanConverter, XamlBrushSerializer. The ids that WPF’s reader names in code are 46 BooleanConverter, 189 DynamicResourceExtension, 195 EnumConverter, 602 StaticExtension, 603 StaticResourceExtension, 634 TemplateBindingExtension, 691 TypeExtension and 744 XamlBrushSerializer. The lists are the reader’s for BAML 0.96; they are not the list of all WPF types (a type that is not in it, such as Calendar, is written with a TypeInfo record of the file and a number of 0 or more).
The list of built-in types and properties is part of the viewer (explorer/formats/xaml/bamltables.js), copied from Baml2006KnownTypes.cs.
Markup extensions
A PropertyWithExtension record writes a property whose value is a markup extension with one argument, without the extension’s object. The extension id has the type of the extension in its low 12 bits (as a built-in type id with the sign dropped: DynamicResourceExtension 189, StaticExtension 602, StaticResourceExtension 603, TemplateBindingExtension 634, TypeExtension 691), and two flags:
- 0x4000: the value id is a type id (an
{x:Type}argument; also used with the other extensions to name a type). - 0x2000: the value id is a static member (an
{x:Static}argument). A positive value id is a property id (the member is a field or property of the declaring type of that entry, such asInt32.MaxValue); a negative one is a system resource id. - Neither flag: for
StaticExtensionthe value is a member as above; forTemplateBindingExtensiona property id; forTypeExtensiona type id; forDynamicResourceExtensionandStaticResourceExtensiona string id (the key).
The ids of the system resources (SystemColors, SystemFonts, SystemParameters and the theme styles of controls) number the SystemResourceKeyID enumeration of WPF in four blocks of ids: the keys of the original enumeration (1 to its end), the same number of ids for the resources themselves (the property rather than its key), then the extended colours as keys, and as resources. An x:Static of SystemColors.ControlTextBrushKey is the first kind.
Static resources
A dictionary item that uses {StaticResource} does not name the key in the item itself: after the item’s key record, the keys section lists the resources the item needs, as OptimizedStaticResource records (the flag byte says whether the key is a string id, a type id or a static member) or as StaticResourceStart blocks (a resource that is an object of its own). In the item, PropertyWithStaticResourceId and StaticResourceId then give the number of the resource in that list, from 0. The viewer resolves the number when it rebuilds the XAML text.
Compact values (PropertyCustom)
The serializer type id of a PropertyCustom record says how the data after it is written. Numbers use a compact double: a type byte, then 1 = zero (no more bytes), 2 = one, 3 = minus one, 4 = a scaled integer (an Int32 that is the value times 1,000,000), 5 = a double (8 bytes, IEEE 754). A writer chooses the scaled integer when the value is a multiple of one millionth that fits an Int32.
| Serializer | The data |
|---|---|
| EnumConverter | UInt32: the value of the enumeration member (a combination of flags is the sum). The enumeration is the property’s type, which the file does not name. |
| BooleanConverter | one byte, 1 for True |
| StringConverter | a string |
| DependencyPropertyConverter | Int16 property id; or, when bit 0x4000 of the serializer id is set, an Int16 type id and a string with the member name (the property is a member of that type) |
| XamlBrushSerializer | a byte: 1 = a known solid colour followed by a UInt32 that is the colour as ARGB (a named colour such as Red is 0xFFFF0000); 2 = another colour, followed by its text as a string (such as #80FF0000) |
| XamlInt32CollectionSerializer | a byte for the kind (1 consecutive, 2 bytes, 3 unsigned shorts, 4 integers), an Int32 count, then for consecutive the first Int32, otherwise count items of the kind’s size |
| XamlPointCollectionSerializer | UInt32 count, then count points of two compact doubles (x, y) |
| XamlPoint3DCollectionSerializer, XamlVector3DCollectionSerializer | UInt32 count, then count items of three compact doubles |
| XamlPathDataSerializer | path geometry: a series of operations ending with the one that closes the data, see below |
Path data
Each operation starts with a byte: the low four bits are the operation and the four high bits are flags (bit 4 = 0x10, 0x20, 0x40, 0x80).
| Code | Operation | Flags | Then |
|---|---|---|---|
| 0 | BeginFigure | 0x10 filled, 0x20 closed, 0x40 and 0x80: the x and y numbers are scaled integers | x, y: an Int32 (the value times 1,000,000) when its flag is set, a compact double otherwise |
| 1 | LineTo | 0x10 stroked, 0x20 smooth join, 0x40 and 0x80 as above | x, y as above |
| 2 | QuadraticBezierTo | as LineTo | the first point as above, then the second as two compact doubles |
| 3 | BezierTo | as LineTo | the first point as above, then two more points as compact doubles |
| 4, 5, 6 | PolyLineTo, PolyQuadraticBezierTo, PolyBezierTo | 0x10 stroked, 0x20 smooth join | Int32 count, then that many points of two compact doubles |
| 7 | ArcTo | as LineTo | the end point as above, a byte (low nibble not zero: large arc; high nibble not zero: clockwise), the size as two compact doubles, the rotation angle as a compact double |
| 8 | Closed | nothing: the end of the data | |
| 9 | FillRule | 0x10 set: non-zero fill rule; clear: even-odd | nothing |
The viewer writes the result in the path mini-language, with F0 or F1 first for the fill rule (even-odd, non-zero).
Known colours
The known colour of a brush is a UInt32 that is the ARGB value of one of 140 named colours (the CSS colour names, AliceBlue to YellowGreen) or Transparent (0x00FFFFFF). The viewer names it by that table, and shows the value in hexadecimal beside the name.