【问题标题】:OnAppearing method of the first child page of a TabbedPage called twice两次调用 TabbedPage 的第一个子页面的 OnAppearing 方法
【发布时间】:2018-02-02 10:53:57
【问题描述】:

我有一个带有两个子页面 PageA 和 PageB 的 TabbedPage(以相同的顺序)。 在启动标签页时,PageA 的 OnAppearing 方法被调用两次。如何防止这种情况发生?

这是 TabbedPage 的示例代码:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:views="clr-namespace:SampleApp.Pages"
         x:Class="SampleApp.TabbedPage1">
    <views:PageA Title="Page A" />
    <views:PageB Title="Page B" />
</TabbedPage>

【问题讨论】:

    标签: c# xamarin xamarin.forms uwp tabbedpage


    【解决方案1】:

    好的,我找到了解决方案。由于示例中的PageA是第一页,所以只要调用主页面的InitializeComponent,就会初始化索引为0的页面。此外,Xamarin.Forms 似乎将 CurrentPage 属性设置为子列表中的第一页,导致 OnAppearing 方法被调用两次。为防止这种情况发生,您可以将 TabbedPage 的 CurrentPage 属性设置为 null。

    示例如下:

    public TabbedPage1()
    {
        InitializeComponent();
        CurrentPage = null;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多