質問

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

        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は常に「非スタイル」に見えます。

役に立ちましたか?

解決

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

(Style) Resources["styleTheke"];

Application.Current.Resources 辞書は、で定義されているリソース向けです App.xaml.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top