我正在使用网格,并试图使控制动态循环。
有3个网格,在单击Grid3控件后,我想获得Grid1和Grid2的控件值。
请参见图片。
任何帮助都是感激不尽的。谢谢!
代码隐藏:
Dictionary<string, string[]> myDictionary3 = _Model.getRoomStatusData(_Model.RoomTypesSel, _Model.StartTimeNames);
//Grid 1 x:Name="timelist"
for (int i = 0; i < _Model.StartTimeNames.Length; i++)
{
Label time = new Label() { Text = _Model.StartTimeNames[i], WidthRequest = 80 };
timelist.Children.Add(time, i, 0);
}
//Grid 2 x:Name="roomtype"
for (int i = 0; i < roomtypes.Length; i++)
{
roomtype.RowDefinitions.Add(new RowDefinition());
Label room = new Label() { Text = _Model.RoomTypesSel[i].Name, WidthRequest = 80 };
roomtype.Children.Add(room, 0, i);
}
List<string[]> roomstatu = new List<string[]>()
{
new string[] {"1","2","3","4","5","6"}, new string[] {"1","2","3","4","5","6"},new string[] {"1","2","3","4","5","6"},new string[] {"1","2","3","4","5","6"},new string[] {"1","2","3","4","5","6"},new string[] {"1","2","3","4","5","6"},new string[] {"1","2","3","4","5","6"},new string[] {"1","2","3","4","5","6"}
};
//Grid 3 x:Name="status"
int index = 0;
foreach (var item in roomstatu)
{
status.RowDefinitions.Add(new RowDefinition());
for (int i = 0; i < item.Length; i++)
{
status.ColumnDefinitions.Add(new ColumnDefinition());
Label statuslabel = new Label() { Text = item[i], WidthRequest = 80};
status.Children.Add(statuslabel, i, index);
}
index++;
}
1条答案
按热度按时间ar7v8xwq1#
首先可以得到用户在状态网格中点击的标签的索引,然后通过索引可以得到标签的行位置和列位置。
我已经做了一个例子,它工作得很好,你可以试试下面的代码: