简体   繁体   English

Xamarin 表单导航延迟

[英]Xamarin Forms Delay in Navigation

I am working on a Xamarin Forms Project and stuck with an issue, where I want to open some popups.我正在处理 Xamarin Forms 项目并遇到一个问题,我想打开一些弹出窗口。 As Forms does not have in build Popups so, I have different XAML pages and I'm loading them inside my MainPage.xaml and changing the visibility when required.由于 Forms 在构建 Popups 中没有,所以我有不同的 XAML 页面,我将它们加载到MainPage.xaml并在需要时更改可见性。

Popup_1.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> 

I have many layouts like Popup_1 which I want them to be shown as popup.我有很多像 Popup_1 这样的布局,我希望它们显示为弹出窗口。 Here's my MainPage.xaml here contains 3 popup layouts.这是我的MainPage.xaml这里包含 3 个弹出式布局。

MainPage.xaml主页.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> 

The problem is when I am trying to navigate to Mainpage.xaml it taking a lot of time to navigate.问题是当我尝试导航到Mainpage.xaml它需要花费大量时间来导航。 Is there any standard solution for this issue?这个问题有标准的解决方案吗? or How can I deal with this delay ?或者我该如何处理这种延迟?

Note: I'm using MVVM binding pattern to change the visibility of layouts.注意:我正在使用 MVVM 绑定模式来更改布局的可见性。

You're right about to use ContentPage to customize your own popup dialog, but the normal way to show this custom dialog is not setting the visibility of the parent element of your dialog.您即将使用ContentPage来自定义您自己的弹出对话框是正确的,但是显示此自定义对话框的正常方法不是设置对话框父元素的可见性。 We need to display it using PushModalAsync and dismiss it using PopModalAsync .我们需要利用来显示它PushModalAsync并使用驳回PopModalAsync

For code sample you can refer to PushModalAsync or PopModalAsync .对于代码示例,您可以参考PushModalAsyncPopModalAsync

I'm not sure what blocks your UI to cause the delay of navigation since you didn't post any code behind of your dialog.我不确定是什么阻止了您的 UI 导致导航延迟,因为您没有在对话框后面发布任何代码。 Anyway, you can try to push and pop a modal page and see if this helps.无论如何,您可以尝试推送和弹出一个模态页面,看看这是否有帮助。

As Forms does not have in build Popups由于表单在构建弹出窗口中没有

Refer this page of documentation请参阅此文档页面

https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/pop-ups/ 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