2011-12-17 9 views
1

私は、スードクゲームグリッドを表示するためのカスタムitemscontrolを持っています。私はそれが9X9グリッドに項目を表示したい。各項目はXとYのプロパティを持ち、グリッドのそのプロパティ位置(グリッドの行とグリッドの列)にバインドしたいと思います。これらのgrid.rowとgrid.columnプロパティをバインドする以外はすべて動作しています。私が硬い値を使うと、何も変わらないので、縛りの誤りではありません。助けてください。:グリッドレイアウトを使ったカスタムItemsControl

<ItemsControl Margin="4" ItemsSource="{Binding Cells, Mode=OneWay}" x:Name="grid"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
       <grid:GridCell Grid.Column="{Binding X}" Grid.Row="{Binding Y}" /> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
       <Grid IsItemsHost="True" Background="Pink"> 
        <Grid.RowDefinitions> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition Height="2" /> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition Height="2" /> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition Width="2" /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition Width="2" /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
        </Grid.ColumnDefinitions> 
      </Grid> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 

編集:私は、細胞が、それらはContentPresenterに包まれているGridの直接の子ではないので、値は無視され

<ItemsControl.ItemTemplate> 
    <DataTemplate> 
      <grid:GridCell Grid.Column="2" Grid.Row="2" /> 
    </DataTemplate> 
</ItemsControl.ItemTemplate> 

答えて

9

例えば使用する場合 何も変化しませんItemsControlItemContainerGeneratorによって作成されました。

ItemContainerStyleを使用して、より高いレベルで値を適用する必要があります。

<ItemsControl.ItemContainerStyle> 
    <Style TargetType="{x:Type ContentPresenter}"> 
     <Setter Property="Grid.Column" Value="{Binding X}" /> 
     <Setter Property="Grid.Row" Value="{Binding Y}" /> 
    </Style> 
</ItemsControl.ItemContainerStyle> 
+0

ありがとうございました。 –

+1

ようこそ。 –

関連する問題