【问题标题】:comparing variabel between 2 file C#比较2个文件C#之间的变量
【发布时间】:2018-06-02 00:25:56
【问题描述】:

我对 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; }
}

【问题讨论】:

  • 在类之间传递值最简单的方法是作为 MarketItemPage() 的构造函数的参数

标签: c# class xamarin.forms static


【解决方案1】:

有几种方法可以实现这一点。一种方法是将项目的Id 传递给MarketItemPage 的构造函数。

有关更多选项,请查看 Passing data when navigating 的 Xamarin 信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多