0

我很困惑,爲什麼當我放入我的Silverlight 4 ListBox ItemsPanel的WrapPanel時,什麼也沒有顯示。如果我只是將ItemsPanel註釋掉,我會得到一個包含文本的小圖片的垂直列表。我將背景顏色添加到WrapPanel中,只是爲了說服自己WrapPanel實際上在那裏。我認爲我錯過了一些頭腦發熱的東西,它是什麼?與Wrappanel的列表框不會顯示元素

​​3210
+0

您是否看到包裝面板或仍然看到白色背景? – 2011-05-28 09:56:03

+0

我沒有看到任何問題,但是這是您的最終項目嗎?並且它是否引用了工具包的所有必需的dll,例如,toolkit.dll依賴於basetoolkit.dll。你的用戶控件將允許你從toolkit.dll中添加wrappanel,但是如果你沒有引用basetoolkit.dll,它可能會給出錯誤,不知道是否是這種情況,但它可能是其中一個原因,你在設計器視圖中看到了什麼?當您運行項目時,您是否在Visual Studio的Output窗口(調試器)中發現了任何其他錯誤? – 2011-05-28 09:58:01

+0

我看到橙色背景。我使用NuGet來添加對'Silverlight Toolkit - 佈局'的引用。我在與此相關的輸出窗口中看不到任何錯誤。 – Thomas 2011-05-29 16:29:58

回答

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> 

這就是我得到: WrapPanel Items

也許,如果您提供更詳細的XAML,可以重現準確的問題並解決問題。

+0

謝謝你。我嘗試將我的東西移動到資源,並複製/粘貼你的ItemsPanel的東西,無濟於事。 – Thomas 2011-05-29 16:54:29