繁体   English   中英

Xamarin 表单导航延迟

[英]Xamarin Forms Delay in Navigation

我正在处理 Xamarin Forms 项目并遇到一个问题,我想打开一些弹出窗口。 由于 Forms 在构建 Popups 中没有,所以我有不同的 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 个弹出式布局。

主页.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 绑定模式来更改布局的可见性。

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

对于代码示例,您可以参考PushModalAsyncPopModalAsync

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

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

请参阅此文档页面

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

暂无
暂无

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

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