Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ComboBox binding to self
Message
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01286103
Message ID:
01286515
Vues:
20
Hi,

>It's acutally even the better solution. You can shorten it like this:
>
>
><ComboBox Width="Auto" Height="Auto" x:Name="ComboBox" IsDropDownOpen="False" SelectedIndex="0"
>	Foreground="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Foreground}">
>    <ComboBoxItem Content="Apples" Foreground="Red" />
>    <ComboBoxItem Content="Oranges" Foreground="Orange"/>
>    <ComboBoxItem Content="Pears" Foreground="Green"/>
></ComboBox>
>
>
>The reason why this solution is better than using ElementName is flexibility: imagine you would use this combobox as a ListBoxItem and every item should have a different name in order to make the binding working. By a RelativeSource binding this would work, too.

Good point - although it wasn't a factor in my scenario. Thanks for clarifying the shorter version - it's what I was originally fumbling for but couldn't get right...

Best,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform