ContentPresenter not showing Usercontrol, how come?
I have a ListBox
th开发者_JS百科at 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
Set TargetType for your ControlTemplate in the Style e. g. <ControlTemplate TargetType="{x:Type ListBoxItem}">
精彩评论