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>
4

1 に答える 1

1

あなたは使用することができますItemsControl

  • ItemsSource行の位置と列の位置のプロパティを持つアイテムのコレクションにをバインドすると、2つのforループを使用してこのようなコレクションを簡単に作成できます。
  • ItemsPanelを作るGrid
  • で、アイテムのプロパティにとをItemContainerStyleバインドできます。Grid.ColumnGrid.Row
  • テンプレートにを設定ItemTemplateします(DataTemplateコントロールをテンプレート化していないため、テンプレートに設定する必要があります)。
于 2012-04-06T19:44:21.823 に答える