私はTabControlを持っており、他のタブの中には「エラー」と呼ばれるものがあります。「ErrorsExist」という特定のプロパティがtrueに設定されている場合、ヘッダーの前景を赤にする必要があります。これが私のコードです:
<TabControl >
<TabControl.Resources>
<conv:ErrorsExistToForegroundColorConverter x:Key="ErrorsExistToForegroundColorConverter"/>
<Style TargetType="{x:Type TabItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Foreground="{Binding Path=ErrorsExist, Converter={StaticResource ErrorsExistToForegroundColorConverter}}" Text="{Binding}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem x:Name="ErrorsTab" Header="Errors">
これが私のコンバーターです:
public class ErrorsExistToForegroundColorConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
switch ((bool)value)
{
case true:
return Brushes.Red;
case false:
return Brushes.Black;
default:
return Binding.DoNothing;
}
}
これには2つの問題があります。
まず、これによりすべてのタブヘッダーが赤に設定され、ErrorsTabタブに対してのみ行う必要があります。
第二に、それはうまくいきません。つまり、コンバーターのConvert()メソッドが呼び出されることはありません。これを手伝ってくれませんか。
ありがとう。