13

ViewModel には、ビュー内のグリッドをバインドするアイテムのリストがあります (アイテムはグリッドの子になります)。リストは、アイテムのビュー モデルのリストです。

グリッドをリストにバインドするにはどうすればよいですか (コードで .children にアクセスできますが、xaml にはアクセスできません)。また、リスト内のビュー モデルのデータ テンプレート (別の xaml ファイル) を指定して、グリッド内で正しくレンダリングされるようにするにはどうすればよいですか。

ありがとう

4

1 に答える 1

23

をGridItemsControlに設定して使用します。ItemsPanel

<ItemsControl ItemsSource="{Binding TheList}">
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <Grid/>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
</ItemsControl>

ItemsControlのでは、および添付のプロパティを項目のプロパティにItemContainerStyleバインドしたい場合があります。Grid.RowGrid.Column

  <ItemsControl.ItemContainerStyle>
    <Style TargetType="{x:Type FrameworkElement}">
        <Setter Property="Grid.Row" Value="{Binding RowIndex}"/>
        <Setter Property="Grid.Column" Value="{Binding ColumnIndex}"/>
    </Style>
  </ItemsControl.ItemContainerStyle>
于 2009-09-08T23:26:44.580 に答える