我如何访问 gridIndex 的内容
我的网格有很多行和列。
看起来像这样。
<Grid x:Name="grid" Grid.ColumnSpan="3" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<rectImg:RectImg Grid.Row="0" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="1"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="2"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="3"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="4"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="5"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="6"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="7"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="8"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="10"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="11"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="12"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="13"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="14"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="15"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="1" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="2" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="3" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="4" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="5" Grid.Column="0"></rectImg:RectImg>
</Grid>
我想在后面的代码上初始化并在这段代码上使用 foreach 或 for :
<rectImg:RectImg Grid.Row="0" Grid.Column="0"></rectImg:RectImg>
我已经尝试了很多方法。但我没有这样做..很多人说“使用Grid.SetColumn和Grid.SetRow”,但它不能应用....
我该如何解决这个问题?
My Grid has many row and column.
It looks like this.
<Grid x:Name="grid" Grid.ColumnSpan="3" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<rectImg:RectImg Grid.Row="0" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="1"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="2"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="3"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="4"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="5"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="6"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="7"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="8"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="9"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="10"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="11"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="12"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="13"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="14"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="0" Grid.Column="15"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="1" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="2" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="3" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="4" Grid.Column="0"></rectImg:RectImg>
<rectImg:RectImg Grid.Row="5" Grid.Column="0"></rectImg:RectImg>
</Grid>
I want to initialize on code behind and use foreach or for on this code:
<rectImg:RectImg Grid.Row="0" Grid.Column="0"></rectImg:RectImg>
I have tried many ways. but i did't do it.. many people say"use Grid.SetColumn and Grid.SetRow" but it can't be applied....
How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了满足您的要求,可以按如下方式完成...
从后面的代码中,您可以在网格子项中添加 RectImg 控件,在此之前确保分配行和列索引。
但这样的设计效率并不高。它实际上应该是一个在其中托管多个 RectImg 控件的 ItemsControl。
像这样......
这里的“local”是MainWindow所在的本地项目命名空间的XAML命名空间。
您的主窗口应如下所示...
请告诉我这是否有帮助。
For the sake of your requirements this can be done as following...
From code behind you can add the RectImg controls in the grid children and before that make sure you assign the Row and Column indices.
But such design is not efficient. It should actually be an ItemsControl hosting multiple RectImg controls in it.
like this....
Here "local" is the XAML namespace of you local project namespace where MainWindow resides.
Your MainWindow should be as below...
Let me know if this helps.