I am using following ItemTemplate in a TabControl to set the content of the tab item and the foreground color of the tab item. Both properties are available in the same ViewModel class:
<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>
As for the 'Name' property everything works as expected. When the property is modified the name on the tab item changes. But for the 'Color' property this does not work. I keep getting
System.Windows.Data Error: 40 : BindingExpression path error: 'Color' property not found on 'object' ''String' (HashCode=2145491359)'. BindingExpression:Path=Color; DataItem='String' (HashCode=2145491359); target element is 'ContentPresenter' (Name=''); target property is 'Foreground' (type 'Brush')
When setting the TextElement.Foreground to a constant color, e.g. "white", it works.
What's wrong with my binding?