views:

148

answers:

1

Hello; I have a listbox that displays a number of usercontrols that are bound to my questions. this is working fine, however i don't want each of the items in the listbox to be selectable, as such i created a blank style and applied it to the ItemContainerStyle. This has resulted in my content to disappear and each item is showing blank. Any ideas?

--Xaml--

<ListBox ItemContainerStyle="{StaticResource noSelect}" Name="lbTasks" Height="180" BorderBrush="#E6E6E6" >
     <ListBox.ItemTemplate>
          <DataTemplate>
               <my:TaskQuestion Question="{Binding Test}" />
          </DataTemplate>
     </ListBox.ItemTemplate>
</ListBox>

--Style--

    <Style x:Key="noSelect" TargetType="{x:Type ListBoxItem}">
    <Setter Property="Margin" Value="2, 2, 2, 0"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <ContentPresenter />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Am i using the content presenter incorrectly?

Tia, Kohan

+3  A: 

Set TargetType for your ControlTemplate in the Style e. g. <ControlTemplate TargetType="{x:Type ListBoxItem}">

viky
Perfect, many thanks.
Kohan