开发者

WPF Themes and TemplateSelectors

开发者 https://www.devze.com 2022-12-12 16:35 出处:网络
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.

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:

  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}"/>
    
0

精彩评论

暂无评论...
验证码 换一张
取 消