Consider the following XAML code:
<StackPanel> <ListBox x:Name="lbColor"> <ListBoxItem Content="Blue"/> <ListBoxItem Content="Green"/> <ListBoxItem Content="Yellow"/> </ListBox> <TextBlock> <TextBlock.Text> <Binding ElementName="lbColor" Path="SelectedItem.Content"/> </TextBlock.Text> <TextBlock.Background> <Binding ElementName="lbColor" Path="SelectedItem.Content"/> </TextBlock.Background> </TextBlock> </StackPanel>
I understand how Text property binding works. Internally it is converted to something like:
textBlock.Text = lbColor.SelectedItem.Content;
But how Background is bound to the same source? This code:
textBlock.Background = lbColor.SelectedItem.Content;
is incorrect. How can it work? BTW, it works and shows correct background color.
The only way I see, is to get System.Windows.Media.Colors property with given name, create SolidColorBrush from it and assign to Background property. But there is nothing in the code which points to this path.