.net Listbox数据模板不工作
我知道我犯了一些愚蠢的错误。但无法解决 这是xaml代码:.net Listbox数据模板不工作,.net,xaml,silverlight-4.0,.net,Xaml,Silverlight 4.0,我知道我犯了一些愚蠢的错误。但无法解决 这是xaml代码: <Border BorderBrush="Red" BorderThickness="3" Grid.Column="0" Grid.Row="0"> <toolKit:ListBoxDragDropTarget AllowDrop="True" > <ListBox Height="85" Width="1
<Border BorderBrush="Red" BorderThickness="3" Grid.Column="0" Grid.Row="0">
<toolKit:ListBoxDragDropTarget AllowDrop="True" >
<ListBox Height="85" Width="120">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="12233" Foreground="AliceBlue"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</toolKit:ListBoxDragDropTarget>
</Border>
屏幕截图是:您正在使用影响数据绑定数据的
DataTemplate
属性。从屏幕截图上看,您似乎在VS designer中,而不是实际运行应用程序。在这种情况下,您可以设置ItemContainerStyle
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<TextBlock Text="12233" Foreground="AliceBlue" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBoxItem>My ListBoxItem</ListBoxItem>
</ListBox>
我的ListBoxItem
如果您只是在测试布局,那么您的
数据模板应该很好,可以通过设置列表框的源来进行测试(例如通过myListBox.ItemsSource
或数据绑定,如果已经设置了该设置)。您需要将ListBoxItem添加到列表框中。您已经定义了ListBox的ItemTemplate,但ListBox没有任何项。