【问题标题】:draw multiple grid square in wpf在wpf中绘制多个网格正方形
【发布时间】:2012-07-22 12:28:13
【问题描述】:

我有一个网格(30 列和 20 行)。每个正方形里面都有一个画布,例如:

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

我必须复制并粘贴 30x20 的正方形。我怎样才能找到更好的方法?请帮帮我。

谢谢!

【问题讨论】:

    标签: wpf grid


    【解决方案1】:

    如果需要命名但没有特定顺序,您可以使用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>
    

    如果您有您的项目列表,请使用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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 2015-06-14
      • 2022-08-11
      • 2013-12-13
      • 2018-05-07
      • 2013-03-31
      • 1970-01-01
      相关资源
      最近更新 更多