Wednesday, April 20, 2011

Five Minute Silverlight 5 Aides-Memoire #1 – Style Setter Binding

Code Snippet
  1. <Grid x:Name="LayoutRoot"
  2.       Background="White">
  3.     <Grid.RowDefinitions>
  4.         <RowDefinition />
  5.         <RowDefinition Height="Auto" />
  6.     </Grid.RowDefinitions>
  7.     <Grid.Resources>
  8.         <Style x:Key="VariableFontTextBlockStyle"
  9.                TargetType="TextBlock">
  10.             <Setter Property="Foreground" Value="DarkOrange" />
  11.             <Setter Property="FontWeight" Value="Bold" />
  12.             <Setter Property="FontSize" Value="{Binding ElementName=FontSizeSlider, Path=Value}" />
  13.         </Style>
  14.     </Grid.Resources>
  15.     <TextBlock x:Name="SampleTextBlock"
  16.                Grid.Row="0"
  17.                HorizontalAlignment="Center"
  18.                VerticalAlignment="Center"
  19.                Style="{StaticResource VariableFontTextBlockStyle}"
  20.                Text="No Mr Bond - I expect you to die" />
  21.     <Slider x:Name="FontSizeSlider"
  22.             Grid.Row="1"
  23.             MaxWidth="500"
  24.             Margin="100,30"
  25.             Maximum="64"
  26.             Minimum="8"
  27.             Value="12" />
  28. </Grid>

SL5AM1

No comments: