locked
Is it possible to Change Default Foreground color ? RRS feed

  • Question

  • Hi Is it possible to Change Default Foreground color for the project ? With C# or in the XAML. Or do I need to change the Foreground on every "text object" ? //MOL
    Thursday, June 17, 2010 4:02 AM

Answers

All replies

  • that's what Style is done for. And Default style can be simply defined for any class, just define the style but do not give it a name. It will apply to all control of the specified class.

    <Style TargetType="TextBlock">
    <Setter Property="Foreground" Value="White" />
    </Style>

    Thursday, June 17, 2010 4:28 AM
  • Hi thanks. But how do I add the Style? //MOL
    Thursday, June 17, 2010 5:47 AM
  • Hi again I try add this to the MainPage.xaml

    <UserControl.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="Red" />
            <Setter Property="FontSize" Value="20" />
        </Style>
    </UserControl.Resources>
      

     

    But it do not work? //MOL

    Thursday, June 17, 2010 6:46 AM
  • You can put that in App.xaml so that implicit style will take effect everywhere in your application.

    Thursday, June 17, 2010 11:44 AM
  •  Hi I try to add "my style" in the App.xaml

     <Application.Resources>

    <Style TargetType="TextBlock">

    <Setter Property="Foreground" Value="Red" />

    <Setter Property="FontSize" Value="40" />

    </Style>

     

    </Application.Resources>

    But it have no effect!

    Any ideas why?

    //MOL

     

    Friday, June 18, 2010 6:17 AM
  • You can set style in the resource dictionary and then add that dictionary to you app.xaml.

    Friday, June 18, 2010 6:28 AM
  • Well, I can't understand what is your problem. Open a new and clean project. In the xaml of mainpage.xaml add the following :

    <UserControl.Resources>
      <Style TargetType="TextBlock">
       <Setter Property="Foreground" Value="#FFFF1700"/>
      </Style>
     </UserControl.Resources> 

    Then, double click a few TextBlock and you'll see they will be all red (the color I selected in the code above).

    I just try it under Blend 4 to be sure of what I'm saying, and that's work.

    Friday, June 18, 2010 1:21 PM
  • Hi

    Then I think I do somthing wrong Tongue Tied.

    If I try to make a new project I do not get Red text Sad

    <UserControl x:Class="Test_Tekst_Farve.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

     

    <UserControl.Resources>

    <Style TargetType="TextBlock">

    <Setter Property="Foreground" Value="Red"/>

    <Setter Property="FontSize" Value="40" />

    </Style>

    </UserControl.Resources>

     

    <Canvas x:Name="LayoutRoot">

     

     

    <TextBlock Text="Test af fil" />

     

    </Canvas>

    </UserControl>

    //MOL

    Monday, June 21, 2010 7:10 AM
  • Hi,

       If you are not using SIlverilght 4 , this approach wont work.

       If you are using SL3 , you may need to use impilict style manager.

       http://weblogs.asp.net/lduveau/archive/2009/11/17/skin-your-silverlight-3-app-with-implicit-style-manager.aspx

    Best Regards

    Thursday, June 24, 2010 2:34 AM