2012-04-06 5 views
1

すべてのセルを同じコントロールで塗りつぶしたい。私が今持っているのはコントロールテンプレートとグリッドです。しかし、私はすべての細胞にコントロールを追加するXamlで簡単な方法を見つけることができません。すべてのグリッドセルをコントロールテンプレートで塗りつぶす

<Window x:Class="AcMidi.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="512" Width="760"> 
    <Window.Resources> 
     <ControlTemplate x:Key="Planet"> 
      <Button Content="Button"></Button> 
     </ControlTemplate> 
    </Window.Resources> 
    <Grid Height="209" Name="grid1" Width="500"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
    </Grid> 
</Window> 

答えて

1

あなたが行postionと列の位置のプロパティを持っているアイテムのコレクションにItemsControl

  • バインドItemsSourceを使用することができ、あなたは:

    この

    は私が今持っているコードです。 2つのforループを持つコレクションを簡単に作成できます。
  • あなたの項目のプロパティにGrid.ColumnGrid.RowをバインドすることができItemContainerStyleItemsPanelGrid
  • してください。
  • ItemTemplateをテンプレートに設定します(テンプレートを作成しないので、DataTemplateにする必要があります)。
関連する問題