我对C编码很新,最重要的是C#,所以我遇到的问题是要了解它是如何工作的。所以我真正想要的是,当你按下一个网格时,你会得到一个唯一的id,这取决于网格中显示的项目,按下网格你将进入一个新的页面,我想显示item.id
档案1
foreach (var item in list)
{
TapGestureRecognizer gridTap = new TapGestureRecognizer();
gridTap.Tapped += (sender, e) =>
{
Navigation.PushModalAsync(new MarketItemPage());
item.Id = GridIdentifier.Grid_id; // item.id is the id of the choosen item = static int in class
};
}
文件2
public void Update()
{
string gridid = GridIdentifier.Grid_id.ToString();
grid.Children.Add(new Label
{
Text = gridid,
FontSize = 16,
FontFamily = "Arial",
TextColor = Color.Red,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center,
HorizontalOptions = LayoutOptions.Center,
});
}
班级
public static class GridIdentifier
{
public static int Grid_id { get; set; }
}