views:

190

answers:

1

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?

A: 

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}"/>
    
Nir
This doesnt make much sense... I dont have ContentPresenters in my templates. Should I? My templates look like this: <DataTemplate x:Key="GopherInfoLine"> <StackPanel Orientation="Horizontal" > <Image Source="Icons\information.png"/> <TextBlock Text="{Binding LineText}" /> </StackPanel> </DataTemplate>
Indrora
OK figured it out. I needed a Style for my ListViewItem with its appropriate setters.
Indrora