简体   繁体   English

如何在Xamarin Forms和XAML中检测Tab显示/隐藏

[英]How to detect Tab show/hide in Xamarin Forms and XAML

I am using following code to implement tabbed page in my xamarin forms app: 我正在使用以下代码在我的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"  });           
    }

}

I need to detect when particular tab is being shown or is it hidden. 我需要检测特定的选项卡何时显示或隐藏。 How can I do this in Xamarin forms? 如何以Xamarin形式进行此操作?

有一个虚拟方法OnCurrentPageChanged重写此方法,然后检查CurrentPage属性

There is TabbedPage.CurrentPage property. 有TabbedPage.CurrentPage属性。 You can either bind your view-model property to it or write code like this: 您可以将view-model属性绑定到该属性,也可以编写如下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM