Question

So I'm going through a style (in this case, WhistlerBlue.xaml) and I'd like to be able to use TemplateSelectors with my data.

However, this seems a fallacy because it just doesnt seem to work! How can I (Aside from carte-blanch commenting out the offending style, the ListBoxItem style) use a DataTemplateSelector with it?

Was it helpful?

Solution

Try adding a binding for the ListBoxItem.ContentTemplateSelector property:

  1. Inside the theme XAML, find the ListBoxItem control template (it's set into the "Template" property inside teh ListBoxItem style).

  2. Find the ContentPresenter element inside the template.

  3. Add the missing binding:

    <ContentPresenter
        x:Name="contentPresenter"
        Content="{TemplateBinding Content}"
        ContentTemplate="{TemplateBinding ContentTemplate}"
        ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" <-- ADD THIS LINE
        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
        Margin="{TemplateBinding Padding}"/>
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top