wpf 了解统一网格控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6197646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding Uniform Grid control
提问by Rohit
I was just trying uniform grid, how it works.
我只是在尝试统一网格,它是如何工作的。
Code :
代码 :
<UniformGrid Name="uniformGrid1" Rows="2" Columns="3">
<Button Content="Rohit" Grid.Row="0" Grid.Column="0" />
<Button Content="asit" Grid.Row="0" Grid.Column="2" />
</UniformGrid>
I found that both buttons are placed adjacent to each other, however there exist a column between them. Why is it so ? (as in uniform grid, each cell has similar size there should be one cell between them)
我发现两个按钮彼此相邻放置,但是它们之间存在一列。为什么会这样?(在统一网格中,每个单元格的大小相似,它们之间应该有一个单元格)
Understood why it is so (by answer) but still curious to konw what's the significance of Attached property - Grid.Row & Grid.Columnif they do nothing ???
理解为什么会这样(通过回答)但仍然想知道附加属性的意义是什么 - Grid.Row 和 Grid.Column如果它们什么都不做???
回答by Kishore Kumar
UniformGrid contains two properties, Rows and Columns, for setting the number of rows and columns. Controls are added to the grid in the order that they are declared. So there will not be any column in between them. In your example you have declared Columns=3 and you have added only two controls. But if you add another control it will place in the end.
UniformGrid 包含两个属性,Rows 和 Columns,用于设置行数和列数。控件按照声明的顺序添加到网格中。所以它们之间不会有任何列。在您的示例中,您已声明 Columns=3 并且仅添加了两个控件。但是如果你添加另一个控件,它会放在最后。
<UniformGrid Name="uniformGrid1"
Rows="2"
Columns="3">
<Button Content="Rohit"
Margin="2" />
<Button Content="asit"
Margin="2" />
<Button Content="asit"
Margin="2" />
</UniformGrid>
回答by Kian
As shown in the MSDN article for a UniformGrid, there is no Grid.Row
or Grid.Column
attached property.
如UniformGrid的MSDN 文章所示,没有Grid.Row
或Grid.Column
附加属性。
Instead, Intellisense may be suggesting it because you have a Grid
further up the document tree. If it were an attached property, it would be far more likely to be called UniformGrid.Row
as that is how attached properties are accessed.
相反,Intellisense 可能会建议它,因为您Grid
在文档树上有更远的位置。如果它是附加属性,则更有可能被调用,UniformGrid.Row
因为这是访问附加属性的方式。