Bling is currently available as a project that you include in your WPF program. Simply add Bling to your solution and add a reference to Bling in your project. The referring project must include standard WPF assemblies, which can be obtained through the "Create WPF Application" Visual Studio 2008 wizard. The referring project will also need to refer to the System.Drawing assembly.

Bling is separated into multiple namespaces, the most important being Bling.DSL and Bling.WPF. A starndard C# file that uses Bling will begin with the following using declarations:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Bling.DSL;
using Bling.WPF;

Other important namespaces include Bling.Util, which contains various utility types and procedures, Bling.Constraints, which is used to create new kinds of constrainable properties, and Bling.Physics, which provides support for UI physics. However, for simple projects the above using declarations are sufficient.

Bling is defined as a bunch of wrappers around WPF classes, where we refer to the wrappers as blings. WPF Blings are stateless and are only used to access enhnaced APIs that operate on underlying WPF objects. A bling can be forgotten (garbage collected) after its functionality is used without consequence, and as a result Bling's use is compatible in conventional WPF applications that utilize conventional C# code and XAML.

The Bling for a WPF object can be obtained by calling the "Bl()" extension method on the object; e.g.,
Label l0 = ...;
LabelBl l1 = l0.Bl();

By convention, "Bl()" extension methods are used to create blings around not only for a WPF object but also for standard data types; e.g., "1d.Bl()" will create a double Bling of type DoubleBl. The type of a bling is then named after the underlying type prepended with "Bl".

A bling provides enhanced properties that mirror the properties of the underlying WPF object. For example, a label bling has a Content property, a Foreground property, and a Font.Size property. These properties can be used in the same way that WPF properties are used; e.g.,
l1.Content = "Hello world!";
l1.Foreground = Brushes.Red;
l1.Font.Size = 80d;

The type of a Bling enhanced property is also a bling. For example, the content of a label bling is an object bling (ObjectBl), the foreground of a label bling is a brush bling (BrushBl), and the size of a font is a double bling (DoubleBl). Values of the bling's underlying type will automatically be converted to the bling's type; e.g., the double 80d will automatically be converted to a double bling if the target type is DoubleBl, while the brush Brushes.Red will automatically be converted into a brush bling (BrushBl). The power of Bling shines through when Blings are assigned to each other, which we will begin to discuss in the section on constraints.

Note that some properties have been refactored where useful. For example, Font properties are accessed through a general "Font" property that contains "Size", "Style", and "Weight" sub-properties, while Border properties are accessed through a general "Border" property that contains "Thickness" and "Brush". In general, whenever properties share a Prefix that is duplicated in multiple classes, we refactor the prefix as a general property.

Additionally, a bling can provide properties that do not exist in WPF directly but are computed as expressions over other properties. For example, a LeftTop point property combines canvas's left and top double properties, while a RightBottom point property is simply LeftTop Size, and a CenterPosition point property is simly LeftTop Size / 2. Although such properties are derived from expressions, they can still be assigned, with the assignment being translated into an assignment of the expression's left-most term.

WPF bling APIs are designed to support WPF objects that are installed on canvases, where layout occurs through constraints rather than through more advanced panels. That is to say, properties in a WPF bling support the WPF object in a canvas, and all of the canvas's attached properties (positions, ZIndex) are properties of a WPF bling. As a matter of convenience, a WPF bling can be created directly and installed on a canvas. Consider the following code:
var thumb = new ThumbBl(canvas) {
  Background = Brushes.Red,
  CanDrag = true,
  RightBottom = canvas.Size,
  ZIndex = 1,
This code creates a thumb bling that is added to the canvas specified in its constructor. On creation, the properties of the bling can be assigned according to C#'s standard property initialization syntax. Unlike standard WPF, when a WPF object is created as a bling, its visual properties are initialized to reasonable values so that the bling will appear on the screen. For example, a thumb has a default size of 10 by 10 pixels so if its size is not set explicitly it will still be displayed. Where appropriate, blings are enhanced with additional properties to make using the bling easier. For example, thumb is enhanced with a "CanDrag" property that when set to true, causes the thumb to be configured so that it can be dragged directly by the user with a mouse.

Last edited Feb 16, 2009 at 7:10 AM by mcdirmid, version 12


No comments yet.