0
votes

I have a grid (30 columns and 20 rows). Each square has a canvas inside like :

Canvas Name="canvas1" Grid.Column="1" Grid.Row="1" Style="{StaticResource ResourceKey=ImagePlacement}

I have to copy and paste for 30x20 square. How can I find the better way? Please help me.

Thanks!

1

1 Answers

0
votes

If a naming but no specific order is desired you can use an UniformGrid:

<UniformGrid Columns="30" Rows="20">
    <UniformGrid.Resources>
        <Style TargetType="Canvas">
            <Setter Property="Style" Value="{StaticResource ResourceKey=ImagePlacement}" />
        </Style>
    </UniformGrid.Resources>
    <Canvas Name="canvas1" />
    <Canvas Name="canvas2" />
    ...
</UniformGrid>

If you have a List of your items use an ItemsControl:

<ItemsControl ItemsSource="{Binding YourItemsList}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="30" Rows="20" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Canvas Style="{StaticResource ResourceKey=ImagePlacement}">
                ... your bounded Content ...
            </Canvas>               
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>