Сначала вам нужно добавить Foreground
и TextChanged
в TextBox:
<TextBox Foreground="{DynamicResource txtColor}" Width="200" Text="asdasd" x:Name="qwerty" TextChanged="TextBox1_TextChanged">
</TextBox>
Затем вы можете динамически изменить передний план текстового поля в событии TextChanged следующим образом:
private void TextBox1_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textBox = sender as TextBox;
if(textBox.Text == "zzz")
{
Application.Current.Resources["txtColor"] = new SolidColorBrush(Colors.Red);
}
}