Considérez le code XAML suivant:données WPF de liaison
<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>
Je comprends comment fonctionne la liaison propriété Text. En interne, il est converti en quelque chose comme:
textBlock.Text = lbColor.SelectedItem.Content;
Mais comment l'arrière-plan est lié à la même source? Ce code:
textBlock.Background = lbColor.SelectedItem.Content;
est incorrect. Comment cela peut-il fonctionner? BTW, cela fonctionne et montre la bonne couleur de fond. La seule façon dont je vois, est d'obtenir la propriété System.Windows.Media.Colors avec le nom donné, de créer SolidColorBrush et d'assigner à la propriété Background. Mais il n'y a rien dans le code qui pointe vers ce chemin.
Merci. Y a-t-il de la documentation à ce sujet? Sans connaître de tels détails, je me sens comme un singe qui tape du jibberish. –
La question sur les convertisseurs intégrés a déjà été répondu ici - http://stackoverflow.com/questions/505397/built-in-wpf-ivalueconverters – Stimul8d