【问题标题】:Can I use ClassId in tabbedpage to differentiate their content我可以在标签页中使用 ClassId 来区分它们的内容吗
【发布时间】:2020-05-19 03:51:32
【问题描述】:

我正在尝试将同一页面用于 TabbedPage 中的 3 个选项卡。但是每个选项卡必须在列表视图中显示不同的数据。有没有办法为每个标签设置一个参数?

例子

    <local:Sales Title="Pending" 
                 Icon="ic_shortcut_home.png"
                 ClassId="pending"/>

    <local:Sales Title="Posted" 
                 Icon="ic_shortcut_home.png"
                 ClassId="posted"/>

    <local:Sales Title="Uploaded" 
                 Icon="ic_shortcut_home.png"
                 ClassId="uploaded"/> 

我尝试使用 ClassId 和 Title 来获得它们的区别,但我在 Sales 类构造函数中检索 ClassId 时遇到问题,还有其他方法可以获得我想要的输出吗?

        public Sales()
        {
            InitializeComponent();
            BindingContext = this;
            salesCollection = new ObservableCollection<Head>();
            initLvw();
            Console.WriteLine(Title); //returns null
            Console.WriteLine(ClassId); // returns null
        }

【问题讨论】:

    标签: xamarin.forms tabbedpage


    【解决方案1】:

    您可以在OnAppearing方法中加载数据:

    protected override void OnAppearing()
    {
        base.OnAppearing();
    
        Console.WriteLine(ClassId + "OnAppearing");
    
        BindingContext = this;
        salesCollection = new ObservableCollection<Head>();
        initLvw();
    
    }
    

    或者在构造函数中用一点delay 加载数据:

    public AboutPage()
    {
        InitializeComponent();
    
        Task.Run(async () =>
        {
            await Task.Delay(200);
            Console.WriteLine(ClassId + "AboutPage");
    
            BindingContext = this;
            salesCollection = new ObservableCollection<Head>();
            initLvw();
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2014-06-03
      • 2016-06-24
      • 1970-01-01
      • 2020-03-21
      • 2020-09-24
      相关资源
      最近更新 更多