I am facing a problem with one of my XBAP (WPF Browser application) projects:
Here I have two list boxes:
Now when I click on the item in the first listbox (on the left side), the foreground changes to white and then changes back to black if another item is selected.
Where as for an item in second list box (right side), when I click on the item, the foreground remains black. This is because the text content itself is contained within Expander control:
Now how do I make the Expander control Foreground color behave similar to when a listbox item is selected/selection is changed? Is there any dependency property which I can use to accomplish this?
Note: I want the second list box (right) to behave exactly similar to the first one (left) with respect foreground color.
Just add Foreground="{TemplateBinding TextElement.Foreground}"
to the elements in the template like this
<DataTemplate DataType="{x:Type l:City}">
<Expander
Header="Click to Expand"
Foreground="{TemplateBinding TextElement.Foreground}"
>
<TextBlock
Text="{Binding Name}"
Foreground="{TemplateBinding TextElement.Foreground}"
/>
</Expander>
</DataTemplate>