2012-04-06 3 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

당신은 행받은 위치 및 열 위치에 대한 속성을 항목 컬렉션에 ItemsControl

  • 바인드 ItemsSource을 사용할 수 있습니다, 당신은 :

    내가 지금 가지고있는 코드입니다 두 개의 for 루프를 사용하여 이러한 컬렉션을 쉽게 만들 수 있습니다.
  • 는에서 ItemsPanelGrid
  • 를 확인합니다 ItemContainerStyle 당신이 당신의 품목의 속성에 Grid.ColumnGrid.Row 바인딩 할 수 있습니다.
  • ItemTemplate을 템플릿에 설정합니다 (컨트롤 템플릿을 만들지 않으므로 DataTemplate이어야 함).