TabControl で次の ItemTemplate を使用して、タブ項目のコンテンツとタブ項目の前景色を設定しています。どちらのプロパティも同じ ViewModel クラスで使用できます。
<TabControl.ItemTemplate>
<DataTemplate>
<DockPanel>
<ContentPresenter
Content="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"
TextElement.Foreground="{Binding Path=Color, Converter={converter:ColorToBrushConverter}, UpdateSourceTrigger=PropertyChanged}"/>
</DockPanel>
</DataTemplate>
</TabControl.ItemTemplate>
「名前」プロパティに関しては、すべてが期待どおりに機能します。プロパティが変更されると、タブ項目の名前が変更されます。しかし、'Color' プロパティの場合、これは機能しません。私は得続けます
System.Windows.Data エラー: 40: BindingExpression パス エラー: 'Color' プロパティが 'object' ''String' (HashCode=2145491359)' に見つかりません。BindingExpression: パス = 色; DataItem='String' (HashCode=2145491359); ターゲット要素は 'ContentPresenter' (Name='') です。ターゲット プロパティは「フォアグラウンド」(タイプ「ブラシ」)
TextElement.Foreground を「白」などの一定の色に設定すると、機能します。
バインディングの何が問題になっていますか?