我很困惑,爲什麼當我放入我的Silverlight 4 ListBox ItemsPanel的WrapPanel時,什麼也沒有顯示。如果我只是將ItemsPanel註釋掉,我會得到一個包含文本的小圖片的垂直列表。我將背景顏色添加到WrapPanel中,只是爲了說服自己WrapPanel實際上在那裏。我認爲我錯過了一些頭腦發熱的東西,它是什麼?與Wrappanel的列表框不會顯示元素
3210
0
A
回答
0
我不明白爲什麼,但切換到我的ItemsSource的ObservableCollection做了詭計。不知道爲什麼事情對默認的ItemsPanel而言會比差異面板表現不同,但它確實如此。
感謝您關注此事。
0
您的項目模板中沒有任何內容 - 它充滿了空白元素。把東西放在那裏,你應該看到結果。例如:
<DataTemplate>
<TextBlock>Test</TextBlock>
</DataTemplate>
+0
對不起僞xaml。我希望缺乏結束標籤能夠使這一點變得清晰。另外,我說如果我將wrappanel註釋掉,事情正確顯示 – Thomas 2011-05-29 16:27:56
0
我一直在使用混合的樣本數據中再現您的情況,我可以看到包裹面板裏面的物品:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
x:Class="ASD_Answer012.MainPage"
Width="640" Height="480">
<UserControl.Resources>
<DataTemplate x:Key="ItemTemplate">
<StackPanel>
<TextBlock Text="{Binding Property1}"/>
<CheckBox IsChecked="{Binding Property2, Mode=TwoWay}"/>
<Image Source="{Binding Property3}" HorizontalAlignment="Left" Height="64" Width="64"/>
</StackPanel>
</DataTemplate>
<ItemsPanelTemplate x:Key="ItemsWrapPanelTemplate">
<toolkit:WrapPanel Background="DarkOrange"/>
</ItemsPanelTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListBox Grid.Column="1" Grid.Row="1" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Collection}" ItemsPanel="{StaticResource ItemsWrapPanelTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>
</Grid>
</UserControl>
這就是我得到:
也許,如果您提供更詳細的XAML,可以重現準確的問題並解決問題。
+0
謝謝你。我嘗試將我的東西移動到資源,並複製/粘貼你的ItemsPanel的東西,無濟於事。 – Thomas 2011-05-29 16:54:29
相關問題
- 1. 元素不顯示與ItemsPanelTemplate
- 2. 列表框不會顯示值
- 3. 不會顯示在列表框中VB
- 4. 元素與顯示:塊不顯示
- 5. Javascript不顯示元素與顯示=「塊」
- 6. Ng表,ng元素重複td元素不顯示列標題
- 7. 顯示數組列表的元素
- 8. 顯示列表中的每個元素
- 9. 僅顯示最近的列表元素
- 10. 我需要突出顯示另一個元素引用的列表框元素
- 11. 用消息框顯示數組列表中的元素
- 12. 顯示列表框中的數組元素c#
- 13. 顯示列表框中的向量元素
- 14. 綁定到列表框,但只顯示選定的元素?
- 15. 使用消息框顯示數組列表中的元素數
- 16. 絕對元素不會顯示
- 17. 爲什麼元素不會顯示onClick?
- 18. jlist元素不會動態顯示
- 19. 列表框不顯示
- 20. 爲什麼我的隱藏元素不會顯示與jquery show()?
- 21. ExtJS組合框不顯示元素
- 22. 僞元素不顯示框陰影后
- 23. ListView將不會顯示陣列中的元素:Android
- 24. 邊框不會顯示,儘管出現在檢查元素
- 25. 元素不顯示
- 26. jQuery的隱藏顯示列表元素與選擇
- 27. 列表中的顯示元素與三個計數器
- 28. 以升序顯示元素列表
- 29. HIde和列表顯示元素
- 30. XMLResponse元素顯示在列表中
您是否看到包裝面板或仍然看到白色背景? – 2011-05-28 09:56:03
我沒有看到任何問題,但是這是您的最終項目嗎?並且它是否引用了工具包的所有必需的dll,例如,toolkit.dll依賴於basetoolkit.dll。你的用戶控件將允許你從toolkit.dll中添加wrappanel,但是如果你沒有引用basetoolkit.dll,它可能會給出錯誤,不知道是否是這種情況,但它可能是其中一個原因,你在設計器視圖中看到了什麼?當您運行項目時,您是否在Visual Studio的Output窗口(調試器)中發現了任何其他錯誤? – 2011-05-28 09:58:01
我看到橙色背景。我使用NuGet來添加對'Silverlight Toolkit - 佈局'的引用。我在與此相關的輸出窗口中看不到任何錯誤。 – Thomas 2011-05-29 16:29:58