I am using a ListBox and a ListBox style from here: http://viblend.com/products/net/wpf/controls/free-wpf-controls.aspx
That looks like this:
<ListBox x:Name="listBox" ItemsSource="{Binding}" Style="{StaticResource Office2010SilverListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}" Content="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
But if I am clicking on an item it gets not marked as selected item.
If i am using no datatemplate all works fine. So does anyone has any idea why?
Here the working example:
<ListBox x:Name="listBox" Style="{StaticResource Office2010SilverListBoxStyle}">
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}">1. Frame</ListBoxItem>
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}">2. Frame</ListBoxItem>
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}">3. Frame</ListBoxItem>
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}">4. Frame</ListBoxItem>
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}">5. Frame</ListBoxItem>
<ListBoxItem Style="{StaticResource Office2010SilverListBoxItemStyle}">6. Frame</ListBoxItem>
</ListBox>-->
Your
DataTemplateshould not contain aListBoxItem, that will be created by theListBoxcontrol already, in your example there will be aListBoxItemin aListBoxItem, confuses selection.Also you should apply the style to the items via
ItemContainerStyle. (As far as i know this only works for auto-generatedListBoxItemswhich are created if you add data either directly or viaItemsSource, if you addListBoxItemsdirectly bothDataTemplateand theItemContainerStylewill be ignored)See also: Data Templating Overview