Question

I am facing a problem with one of my XBAP (WPF Browser application) projects:

Here I have two list boxes:

  • One a simple list containing text content
  • Second one containing an expander as each item:

alt text http://i44.tinypic.com/117bpj4.jpg

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:

alt text http://i39.tinypic.com/124vn6u.jpg

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top