繁体   English   中英

列表框数据模板不起作用

[英]Listbox datatemplate not working

我知道我犯了一些愚蠢的错误。 但无法解决。

这是xaml代码:

 <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设计器中,而不是实际在运行该应用程序。 在这种情况下,您可以设置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>

如果您只是在测试布局,则您的DataTemplate应该很好,并且可以通过设置ListBox的源进行测试(例如,通过myListBox.ItemsSource或通过数据绑定进行设置)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM