Johann
Johann

Reputation: 523

xaml - change StandardStyles programmatically

I am working on a Windows 8 App using xaml/c#. I need to change the PageHeaderTextStyle (defined in StandardStyles.xaml).

This is my PageHeaderTextStyle definition:

<Style x:Key="PageHeaderTextStyle" TargetType="TextBlock" BasedOn="{StaticResource HeaderTextStyle}">
    <Setter Property="TextWrapping" Value="NoWrap"/>
    <Setter Property="VerticalAlignment" Value="Bottom"/>
    <Setter Property="Margin" Value="0,0,30,40"/>
    <Setter Property="Foreground" Value="White"/>
</Style>

How would you change the Foreground Attribute programmatically to "Black"?

Upvotes: 1

Views: 734

Answers (1)

Jennifer Marsman - MSFT
Jennifer Marsman - MSFT

Reputation: 5225

Are you sure that you need to change it programmatically?

You can load the style normally by including code like the below in your XAML. You can extend the existing PageHeaderTextStyle definition by changing the "BasedOn" property. Now "myPageHeaderTextStyle" will be exactly like PageHeaderTextStyle, only with the changes you specify.

<Style x:Key="myPageHeaderTextStyle" TargetType="TextBlock" BasedOn="{StaticResource PageHeaderTextStyle}">
    <Setter Property="Foreground" Value="Black"/>
</Style>

If you do need to change it programmatically, you can use SetValue on the Style class (which is what your "myPageHeaderTextStyle" object is).

Upvotes: 1

Related Questions