Changing colour of text in a textblock via a trigger

Posted by Sike12 on Stack Overflow See other posts from Stack Overflow or by Sike12
Published on 2013-10-18T15:51:02Z Indexed on 2013/10/18 15:53 UTC
Read the original article Hit count: 185

Filed under:
|
|
|
|

Here is my Xaml

 <Window.Resources>
    <sampleData:MainWindow x:Key="DataSource"/>
    <DataTemplate x:Key="bobReferencer">                      
        <TextBlock Text="{Binding Name}" >
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding HasErrors}" Value="true">
                          //what goes in here?
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>                                            
    </DataTemplate>    
</Window.Resources>

Codebehind (the one xaml references)

public class bob
{

    public string Name
    {
        get;
        set;
    }

    public bool HasErrors
    {
        get;
        set;
    }

Basically what i want to do is if the HasErrors is true then i want the Name to appear in Red via the trigger. But my xaml is not properly formed. Any suggestions on this? I also looked into this link but didn't help much.
How can I change the Foreground color of a TextBlock with a Trigger?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET