Sunday, May 3, 2009

Defining and using styles in Silverlight

Defining and using styles in Silverlight



Lets take practical scenario for Styles in Silverlight.

Silverlight allows re-useable styles to be created to avoid duplication:


<Button x:Name="btnSubmit" FontFamily="Arial"
FontWeight="Bold" Width="100" Height="25"
Margin="10" />

<Button x:Name="btnCancel" FontFamily="Arial"
FontWeight="Bold" Width="100" Height="25"
Margin="10" />

We can also create Global Styles using app.xaml file


<Application.Resources>
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Width" Value="100" />
</Style>
</Application.Resources>


Applying Styles to Controls:

With the help of Style property we can apply the global style to the properties:

<Button x:Name="btnSubmit" Content="Submit"
Click="btnSubmit_Click"
Style="{StaticResource ButtonStyle}" />

No comments:

Post a Comment