Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:09+00:00 2026-05-26T00:54:09+00:00

Why TextBlock remains black? <Window x:Class=WpfApplication4.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Window.Resources> <Style TargetType=TextBlock

  • 0

Why TextBlock remains black?

<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style TargetType="TextBlock" x:Key="style">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}" Value="True">
                    <Setter Property="Foreground" Value="Red" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel>
        <TextBlock Text="Test" Tag="True" Style="{StaticResource style}" />
    </StackPanel>
</Window>

Update: Ok now I have another problem. The style does not react on property change:

<Window x:Class="WpfApplication4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style TargetType="TextBlock" x:Key="style">
            <Style.Triggers>
                <Trigger Property="Tag" Value="True">
                    <Setter Property="Foreground" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel>
        <TextBlock Text="{Binding Prop}" Tag="{Binding Prop}" Style="{StaticResource style}" x:Name="text" />
        <Button Content="Test" Click="Button_Click" />
    </StackPanel>
</Window>

Backing Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.ComponentModel;

namespace WpfApplication4
{
    public partial class MainWindow : Window
    {
        private MyClass a = new MyClass();

        public MainWindow()
        {
            InitializeComponent();
            DataContext = a;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            a.Prop = true;
            a.OnPropertyChanged("Prop");
        }
    }

    public class MyClass : INotifyPropertyChanged
    {
        public bool Prop { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
        public virtual void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
}

TextBlock’s text changes but color does not

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:54:10+00:00Added an answer on May 26, 2026 at 12:54 am

    Change it to Property Trigger

        <Style TargetType="TextBlock" x:Key="style">
            <Style.Triggers>
                <Trigger Property="Tag" Value="True">
                    <Setter Property="Foreground" Value="Red" />
                </Trigger>
            </Style.Triggers>
        </Style>
    

    TemplatedParent works inside a ControlTemplate. Your Binding is incorrect. Thats why it doesn’t work.

    If you want to use DataTrigger for some reason then the correct Binding would be

    <DataTrigger Binding="{Binding Tag,RelativeSource={RelativeSource Self}}" Value="True">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: <Window x:Class=ScrollTest.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=450 Width=525> <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility=Visible ScrollViewer.VerticalScrollBarVisibility=Visible> <Grid>
How to access textBlock from another xaml window? I have the Main Page and
I have a default TextBlock style defined in App.xaml, which seems to also affect
I have a TextBlock on my main window. I would like to bind it's
This Textblock, defined below, shows when the window first loads because it has no
I have a textblock in my XAML where the Visibility is bound to a
I have a TextBlock in my XAML that has its text bound to a
I have a TextBlock that I need to autosize to the width of a
I have a databound TextBlock control (which is being used inside a DataTemplate to
The following textblock wraps and trims as expected. The elipsis ... is displayed when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.