いいえ、コードが必要です。このコードは、コンバータに次のようになります。
<TextBox x:Name="_textBox1"/>
<TextBox Foreground="{Binding Text, ElementName=_textBox1, Converter={StaticResource ForegroundConverter}}"/>
またはビューモデルで:
public string FirstText
{
//get/set omitted
}
public string SecondText
{
get { return _secondText; }
set
{
if (_secondText != value)
{
_secondText = value;
OnPropertyChanged("SecondText");
OnPropertyChanged("SecondTextForeground");
}
}
}
public Brush SecondTextForeground
{
get { return FirstText == SecondText ? Brushes.Red : Brushes.Black; }
}
おかげで、viewmodelのコードは便利ですが、私は前のパターンに会ったことがありません。私はその後、コンバータのために行くだろう。 – Dabblernl