Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ComboBox binding to self
Message
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01286103
Message ID:
01286515
Views:
18
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
Previous
Reply
Map
View

Click here to load this message in the networking platform