2012-02-07 4 views
0

を表示していない:のListBoxは、データ

<ItemsControl ItemsSource="{Binding Path=.}"> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Vertical"> 
          <TextBlock FontWeight="Bold" Text="{Binding Category}" /> 
          <TextBlock Text=", " /> 
          <TextBlock Text="{Binding Title}" /> 
          <TextBlock Text=" " /> 
          <Label Content="{Binding ImageUrl}" Foreground="Blue" /> 
         </StackPanel> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
      </ItemsControl> 

と次のように表示さ空の行(そこdataitemsと同じ数の):

<ListBox ItemsSource="{Binding Path=.}"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Orientation="Vertical"> 
          <TextBlock FontWeight="Bold" Text="{Binding Category}" /> 
          <TextBlock Text=", " /> 
          <TextBlock Text="{Binding Title}" /> 
          <TextBlock Text=" " /> 
          <Label Content="{Binding ImageUrl}" Foreground="Blue" /> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
+0

明示的に 'DataTemplate DataType'を設定する必要がありますか? –

答えて

1
  1. はあなたのゲッターにブレークポイントを入れてみてくださいカテゴリ。ヒットしますか?
  2. VSの出力ウィンドウを見て、バインディングエラーが表示されますか?

次のコードを使用して、Blendでテストアプリを作成しました。どちらの場合でもリストが表示されます。だからあなたの他のコード(バインディング、コードビハインド、ViewModelなど)に問題があるかもしれませんが、ListBoxとItemsControlの両方が正しく配線されていれば動作するはずです。

<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}, Path=Collection}"> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
     <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 

    <ItemsControl Grid.Row="0" ItemsSource="{Binding Path=.}"> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Vertical"> 
         <TextBlock FontWeight="Bold" Text="{Binding Category}" /> 
         <TextBlock Text=", " /> 
         <TextBlock Text="{Binding Title}" /> 
         <TextBlock Text=" " /> 
         <Label Content="{Binding ImageUrl}" Foreground="Blue" /> 
        </StackPanel> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 

     <ListBox Grid.Row="1" ItemsSource="{Binding Path=.}"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Vertical"> 
         <TextBlock FontWeight="Bold" Text="{Binding Category}" /> 
         <TextBlock Text=", " /> 
         <TextBlock Text="{Binding Title}" /> 
         <TextBlock Text=" " /> 
         <Label Content="{Binding ImageUrl}" Foreground="Blue" /> 
        </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 
</Grid>