2011-12-22 6 views
3

私の環境はWindows Phone 7.1です。ListBoxとしてのキャンバスItemTemplate

 <ListBox ItemsSource="{Binding Path=Items}"> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <Canvas Background="Black" /> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Canvas Width="200" Height="400" 
        Canvas.Top="400"> <====== This is not working 
        ... Some content ... 
       </Canvas> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 

CanvasItemsPanelようがありListBoxあり:

は、私は、次のコードを持っています。

ListBoxItems自体もCanvasです。 ListBoxItemsCanvas.Top =400に設定した場合、ItemsPanelに400のオフセットで表示されます。

enter image description here

アレント理由:これは動作しない残念ながら、アイテムが(ItemsPanelが黒である、カラフルな長方形がリストアイテムである)、このイメージに示すように、0のオフセットでレンダリングさ

ListBoxItemsは、オフセットが400?あなたのListBox

<ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
    </Style> 
</ListBox.ItemContainerStyle> 

にこれを追加すること

答えて

4

あなたはListBoxItemsない実際のアイテム

あなたdatatemplatedオブジェクトが ListboxItems

ListBox 
    Canvas <- your itemtemplate 
    ListBoxItem 
     Canvas <- your datatemplate 

液に包まれていることを忘れてはいけない項目パネルとしてキャンバスを使用しての内容にCanvas.Topを設定しています:

<ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
    <Setter Property="Canvas.Top" Value="400"/> 
    </Style> 
</ListBox.ItemContainerStyle> 
+0

あなたのソリューションは動作しますが、今はwp7のsilverlightがbindinをサポートしていないことに気付きましたg:ItemContainerStyle、aaaarrrrgh:/ – thumbmunkeys

+1

いいえ、バインディングは残念ながら銀色のスタイルでサポートされていません(まだ) SL5にはそれらがありますので、私はWP12でも何かもそうです。 –

+0

hehe、私はそれを待つことができないと思う:) – thumbmunkeys

2

てみあなたが見ているので、黒の領域はListBoxではなく、あなたのListBoxItem。 "一般的に知られているバグ"のため、上記のコードを追加しない限り、それでも呼び出すことができれば、ListBoxItemは伸びません。

関連する問題