I would like to add a custom style to a generated textblock.
TextBlock title = new TextBlock();
title.Style = (Style) Application.Current.Resources["styleTheke"];
title.Text = "test";
stackMenu.Children.Add(title);
This style is defined in
<phone:PhoneApplicationPage.Resources>
<Style x:Key="styleTheke" TargetType="TextBlock">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeLarge}"/>
<Setter Property="Foreground" Value="{Stati开发者_Python百科cResource PhoneAccentBrush}"/>
</Style>
</phone:PhoneApplicationPage.Resources>
However .. the Textblock always appears "unstyled".
If the resource is in the same page then you can refer to it via:
(Style) Resources["styleTheke"];
The Application.Current.Resources
Dictionary is for resources (typically) defined in App.xaml
.
精彩评论