This is a mirror of official site: http://jasper-net.blogspot.com/

Styles In Silverlight: Manipulating At Runtime

| Friday, November 5, 2010
This article is part 4 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 and Styles in Silverlight – Further Advanced Topics.
This part of the series explores manipulating, merging and modifying Styles at runtime. Manipulation of Styles runtime is quite an uncommon scenario and is not really documented, this article tries to cover all important aspects of it.

Modifying Styles Runtime: The IsSealed Property

Modifying the Setters of a Style can only be done if the IsSealed property is set to false. This property is false when the Style is created and is set to true once the Style is applied to any element in the visual tree. Thus it’s safe to say that Styles are a immutable in a special way: they can only be modified until applied to any element in a visual tree.

Trying to modify a Style that is sealed (IsSealed property set to true) can result in multiple errors:

  • If trying to modify the value of a Setter in the Style, an UnauthorizedAccessException to be thrown with the error message Attempted to perform an unauthorized operation.
  • If trying to add another Setter to the Style, an Exception will be thrown with the (not so informative) error message Error HRESULT E_FAIL has been returned from a call to a COM component.
  • When removing a Setter from the Style’s Setters, no exception is thrown, but the operation will have no result.

Read more: Visiblox

Posted via email from .NET Info

0 comments: