【问题标题】:How to detect Tab show/hide in Xamarin Forms and XAML如何检测 Xamarin 表单和 XAML 中的选项卡显示/隐藏
【发布时间】:2016-08-30 19:52:32
【问题描述】:

我正在使用以下代码在我的 xamarin 表单应用程序中实现选项卡式页面:

public class MainApp : TabbedPage
{
    public MainApp ()
    {
        this.Children.Add (new PanicPage{Title="Panic", Icon="icon_panic" });
        this.Children.Add (new StatusPage{Title="Status", Icon="icon_status" });
        this.Children.Add (new ConfigPage{Title="Config", Icon="icon_config"  });           
    }

}

我需要检测特定选项卡何时显示或隐藏。如何在 Xamarin 表单中执行此操作?

【问题讨论】:

    标签: c# xamarin xamarin.ios xamarin.forms


    【解决方案1】:

    有一个虚方法 OnCurrentPageChanged 覆盖它,然后检查 CurrentPage 属性

    【讨论】:

      【解决方案2】:

      有 TabbedPage.CurrentPage 属性。您可以将视图模型属性绑定到它,也可以编写如下代码:

      this.PropertyChanged += (sender, e) => {
          if (e.PropertyName == "CurrentPage")
          {
              //TODO
          }
      };
      

      【讨论】:

      • 例如在现有代码中添加子页面之前。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      相关资源
      最近更新 更多