【问题标题】:Xamarin Forms Delay in NavigationXamarin 导致导航延迟
【发布时间】:2017-01-02 07:59:54
【问题描述】:

我正在开发一个 Xamarin Forms 项目,但遇到了一个问题,我想在其中打开一些弹出窗口。由于 Forms 在构建弹出窗口中没有,所以我有不同的 XAML 页面,我将它们加载到我的 MainPage.xaml 中,并在需要时更改可见性。

Popup_1.xaml

<?xml version="1.0" encoding="utf-8" ?>
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x=http://schemas.microsoft.com/winfx/2009/xaml
x:Class="ABC.Views.Popup_1"> 

<StackLayout >
<Label Text="{Binding FirstName}" VerticalOptions="CenterAndExpand" HorizontalOptions="StartAndExpand" Font="Large" TextColor="Black" />
</StackLayout>

</StackLayout> 

我有许多布局,例如 Popup_1,我希望它们显示为弹出窗口。这是我的MainPage.xaml,这里包含 3 个弹出布局。

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPagexmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x=http://schemas.microsoft.com/winfx/2009/xaml
xmlns:controls="clr-namespace:ABC.Views;assembly=ABC"
x:Class="ABC.Views.MainPage"> 

<AbsoluteLayout BackgroundColor="Transparent" Padding="10" IsVisible="{Binding ShowPopup_1}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" >
        <StackLayout Orientation="Horizontal" BackgroundColor="Transparent"   AbsoluteLayout.LayoutBounds="0.5, 0.5, -1, -1" AbsoluteLayout.LayoutFlags="PositionProportional" >
            <controls:Popup_1   />
        </StackLayout>
    </AbsoluteLayout>


<AbsoluteLayout BackgroundColor="Transparent" Padding="10" IsVisible="{Binding ShowPopup_2}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" >
        <StackLayout Orientation="Horizontal" BackgroundColor="Transparent"   AbsoluteLayout.LayoutBounds="0.5, 0.5, -1, -1" AbsoluteLayout.LayoutFlags="PositionProportional" >
            <controls:Popup_2   />
        </StackLayout>
    </AbsoluteLayout>

<AbsoluteLayout BackgroundColor="Transparent" Padding="10" IsVisible="{Binding ShowPopup_3}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" >
        <StackLayout Orientation="Horizontal" BackgroundColor="Transparent"   AbsoluteLayout.LayoutBounds="0.5, 0.5, -1, -1" AbsoluteLayout.LayoutFlags="PositionProportional" >
            <controls:Popup_3  />
        </StackLayout>
    </AbsoluteLayout>

</ContentPage> 

问题是当我尝试导航到Mainpage.xaml 时,导航需要花费大量时间。这个问题有没有标准的解决方案?或者我该如何处理这种延迟?

注意:我正在使用 MVVM 绑定模式来更改布局的可见性。

【问题讨论】:

    标签: xaml xamarin xamarin.forms popup


    【解决方案1】:

    您将使用ContentPage 来自定义您自己的弹出对话框是对的,但是显示此自定义对话框的正常方法是不设置对话框的父元素的可见性。我们需要使用PushModalAsync 显示它并使用PopModalAsync 关闭它。

    代码示例可以参考PushModalAsyncPopModalAsync

    我不确定是什么阻止了您的 UI 导致导航延迟,因为您没有在对话框后面发布任何代码。无论如何,您可以尝试推送和弹出一个模态页面,看看是否有帮助。

    【讨论】:

      【解决方案2】:

      由于表单在构建弹出窗口中没有

      参考本页文档

      https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/pop-ups/

      【讨论】:

      • 这些是唯一的警报框或操作表。不是我们项目中需要的弹出窗口。我们需要拥有自己的布局,并将不同的字段绑定到我们的 ViewModel。
      猜你喜欢
      • 2020-09-23
      • 2014-04-24
      • 1970-01-01
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多