0

生成されたテキストブロックにカスタムスタイルを追加したいと思います。

        TextBlock title = new TextBlock();
        title.Style = (Style) Application.Current.Resources["styleTheke"];
        title.Text = "test";
        stackMenu.Children.Add(title);

このスタイルはで定義されています

 <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="{StaticResource PhoneAccentBrush}"/>
  </Style>
 </phone:PhoneApplicationPage.Resources>

ただし、..Textblockは常に「スタイルなし」で表示されます。

4

1 に答える 1

3

リソースが同じページにある場合は、次の方法でリソースを参照できます。

(Style) Resources["styleTheke"];

辞書は、Application.Current.Resourcesで定義されたリソース(通常)用ですApp.xaml

于 2010-12-21T14:10:58.057 に答える