开发者

Add a style to a generated TextBlock

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜