WPF Themes and TemplateSelectors
So I'm going through a style (in this case, WhistlerBlue.xaml) and I'd like to be able to use Templ开发者_开发百科ateSelectors 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?
Try adding a binding for the ListBoxItem.ContentTemplateSelector property:
Inside the theme XAML, find the ListBoxItem control template (it's set into the "Template" property inside teh ListBoxItem style).
Find the ContentPresenter element inside the template.
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}"/>
精彩评论