Silverlight 2 Beta 1 Hints

Remember, it is a beta so there are going to be some things that are by design and others which just need temporary workarounds. Here are some things I learned when developing and testing some of the controls delivered as part of the Silverlight 2 Beta 1 SDK.

1. Unlike WPF, the xaml in Silverlight 2 is parsed at runtime, not compile time. (By Design)

 

2. The Style property can only be set once on a control. If you are creating a custom control don't set the Style property in the constructor or nobody will be able to style your control.

 

3. Setters in styles do not override any properties set in code. For example, if the constructor of a custom control calls this.Template = someTemplate, then there is no way for a Setter in a style to change the Template property. However, setting the property directly in xaml does override the value set in constructor. (By Design)

 

4. Bindings using dependency properties as sources do not notify the target when the source changes. To workaround this issue temporarily, you should create a business object that implements the INotifyPropertyChanged interface and can be used as a proxy for any dynamic data binding that you may need to do.

 

5. If you set the Template attribute of a control (whether through a Setter property in a Style or by directly setting the Template property) you will need to redefine the animation storyboards to get the state transition effects (e.g. MouseOver). For examples of the default templates from which you can copy and paste, check out https://msdn2.microsoft.com/en-us/library/cc278075(vs.95).aspx . (By Design)

 

6. Anything that uses a ContentControl to display text (like Button) cannot simply use styles to change the FontFamily, FontStretch, FontSource, FontStyle, and FontWeight properties. This is a bug that will be fixed in future releases. Instead, you will have to explicitly set those properties on each instance of the element. For example

<Style x:Name="topLink" TargetType="HyperlinkButton">

    <Setter Property="FontSize" Value="24" />

    <Setter Property="Foreground" Value="#000000" />

</Style>

<HyperlinkButton Style="{StaticResource topLink}" FontFamily="Verdana"/>

 

7. You cannot set the Style property for the TextBox or (correction) WatermarkedTextBox controls because the controls currently set the Style in the constructor (see #3). To change the appearance of these controls you need to set the Template property explicitly

<WatermarkedTextBox  Template="{StaticResource wtbTemplate}"/>

8. You can only call the Begin() method on a storyboard after the object has been added to the visual tree. Specifically, if you construct a brand new control but don’t add it to a visible parent, calling Begin() on a storyboard affecting that control will throw an exception.

Comments