本文介绍了将UserControl绑定为列表框中的项目的可视错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个来源: I have a source which is:private ObservableCollection<Tuple<string,WrapPanel>> _list = new ObservableCollection<Tuple<string, WrapPanel>>(); 我还有一个列表框: Also I have a Listbox : <ListBox SelectionMode="Single" x:Name="Display" VerticalAlignment="Top" HorizontalAlignment="Stretch" MinHeight="100" MinWidth="700" MaxHeight="250" 我将itemssource从这个listboz设置为我的收藏源: I set the itemssource from this listboz to my collection source :Display.ItemsSource = _List; 我想在我的列表框中显示WrapPanels(Item2)的内容。我无法找到正确可视化这些wrapPanels障碍物的方法。 我尝试了不同的东西,以正确显示这些WrapPanels <! - 1 - > I would like to display the content of WrapPanels ( Item2) into my listbox. I can not find the way to correctly visualize those wrapPanels obsjects .I have tried different things in order to visualize those WrapPanels correctly<!--1--> <ListBox SelectionMode="Single" x:Name="MFPanelsDisplay" VerticalAlignment="Top" HorizontalAlignment="Stretch" MinHeight="100" MinWidth="700" MaxHeight="250" > <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel IsItemsHost="True" DataContext="{Binding}" /> </ItemsPanelTemplate> </ListBox.ItemsPanel></Listbox> <! - 2 - > <!--2--><ListBox SelectionMode="Single" x:Name="MFPanelsDisplay" VerticalAlignment="Top" HorizontalAlignment="Stretch" MinHeight="100" MinWidth="700" MaxHeight="250" DisplayMemberPath="Item2"/><!--3--></ListBox.ItemTemplate> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <WrapPanel Grid.Column="0" Binding="{Binding Item2}" /> <TextBlock Grid.Column="1" Text="{Binding Item1}"/> </Grid> </DataTemplate> </ListBox.ItemTemplate> 结果总是: System.Windows.Controls.WrapPanel System.Windows.Controls.WrapPanel System.Windows.Controls.WrapPanel System.Windows.Controls.WrapPanel 任何帮助都会很好。 The result is always :System.Windows.Controls.WrapPanelSystem.Windows.Controls.WrapPanelSystem.Windows.Controls.WrapPanelSystem.Windows.Controls.WrapPanelAny help would be good.推荐答案 我刚刚找到了我要找的东西: I just found what I was looking for :<ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <ContentControl Grid.Column="0" Content="{Binding Item2}" /> <TextBlock Grid.Column="1" Text="{Binding Item1}"/> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> ContentControl是显示的关键它正确ContentControl was the key for display it correctly 这篇关于将UserControl绑定为列表框中的项目的可视错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 17:06