Search code examples
xamlwindows-phone

Is it possible to change windows phone theme styles (eg: PhoneTextNormalStyle)


Is it possible to change PhoneTextNormalStyle from code behind ? I tried in ways but no luck.

I have already used this style in many places in my app . Now i want to change foreground color . How can i do this without changing all the places in xaml


Solution

  • You can create a custom style on your App.xaml based on the PhoneTextNormalStyle and just adapt the Foreground to suit your needs:

    <Style x:Key="RedPhoneTextNormalStyle" BasedOn="{StaticResource PhoneTextNormalStyle}">
        <Setter Property="Foreground" Value="Red"/>
    </Style>
    

    Then adapting the current style calls to the new one should be fairly easy (search & replace)

    <TextBlock x:Name="ApplicationTitle" 
                       Text="APP NAME" 
                       Style="{StaticResource RedPhoneTextNormalStyle}"/>
    

    The advantage of using a custom style is that you can always extend it if you need to add more functionality to it, as well as use it as a base for other styles