Visiblox » Archive for August 2010

Archive for August 2010

Styles In Silverlight: Further Advanced Topics

Thursday, August 19th, 2010

This article is part 3 of 4 in a series covering everything that I think is worth knowing about styles in Silverlight. The previous parts of the series are Styles in Silverlight: an Introduction and Styles in Silverlight – Inheritance, Precedence and Other Advanced Topics.

This part of the series explores some further advanced topics: data binding, change notification, declaring styles in code behind and some other useful notes on styles.

Style is a Dependency Property

The Style property is a dependency property. This means that they give you some extra features that CLR properties would not. The features that can be used in case of the Style dependency property are the following:

  • Data binding
  • Property changed notifications
  • ClearValue

Note that dependency properties have two other important features that can’t be used with the Style dependency property: animation and styles:

  • The Style property can’t be animated as it’s value type isn’t supported by any Timeline derived animation type.
  • Styles can’t be applied to the Style dependency property… because this is the property that styles need to be applied through (all dependency properties can be styled except for Style).

Data binding

As Style is a dependency property it can be data binded – even though there seem to be very few real world examples when this functionality would actually be needed.

The following example demonstrates how this feature works. Two Ellipses are used: LeftEllipse and RightEllipse. RightEllipse binds its style to LeftEllipse so whenever the style of LeftEllipse changes, so does the style of RightEllipse. When clicking on the button it changes the style of LeftEllipse and thus through the binding the style of RightEllipse is changed as well:

The code (XAML):
(more…)


Advanced Data Visualisation - Powered by Microsoft® Silverlight™ and WPF
© Scott Logic Limited 2011. All rights reserved. Terms of Use | About Us