C# WPF-如何用正方形填充窗口
嘿,伙计们,我有一个wpf应用程序,我想制作一个100x100的正方形网格,并能够在我的代码中将其视为一个普通的集合(列表、数组等)C# WPF-如何用正方形填充窗口,c#,wpf,C#,Wpf,嘿,伙计们,我有一个wpf应用程序,我想制作一个100x100的正方形网格,并能够在我的代码中将其视为一个普通的集合(列表、数组等) 在WPF中,如果不写入10000次,我怎么能做到这一点呢?您可以尝试使用WrapPanel与ItemsControl组合来实现这一点: <ItemsControl x:Name="RectanglesItemsControl"> <ItemsControl.ItemsPanel> <ItemsPanelTempl
在WPF中,如果不写入
10000次,我怎么能做到这一点呢?您可以尝试使用WrapPanel
与ItemsControl
组合来实现这一点:
<ItemsControl x:Name="RectanglesItemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="myNamespace:MyType">
<Rectangle Width="{Binding Width}" Height="{Binding Height}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
编辑:您可以将
WrapPanel
替换为您想要的任何内容,您也可以使用
来拥有100行和100列。您可以尝试将WrapPanel
与项控件结合使用来完成以下操作:
<ItemsControl x:Name="RectanglesItemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="myNamespace:MyType">
<Rectangle Width="{Binding Width}" Height="{Binding Height}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
编辑:你可以用你想要的任何东西替换WrapPanel
,你也可以使用
来拥有100行和100列。要制作WrapGrid
100x100,你还需要设置一些属性。是的,你也可以使用UniformGrid
来实现这一点。我将对其进行编辑以使WrapGrid
100x100,您还需要设置一些属性。是的,您也可以使用UniformGrid
来实现。我会编辑的