Xamarin形式的导航延迟 [英] Xamarin Forms Delay in Navigation
问题描述
我正在研究Xamarin表单项目,但遇到一个问题,我想在其中打开一些弹出窗口.由于Forms在构建Popups中没有,所以我有不同的XAML页面,并且将它们加载到MainPage.XAML中,并在需要时更改可见性.
I’m working on a Xamarin Forms Project and stuck with an issue, where I want to open some popups. 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.
**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个弹出式布局.
I have many layouts like Popup_1 which I want them to be shown as popup. Here’s my MainPage.XAML here contains 3 popup layouts.
**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绑定模式来更改布局的可见性
The problem is when I’m trying to navigate to Mainpage.XAML it taking lot of time to navigate. 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
推荐答案
您正确地打算使用ContentPage
来定制您自己的弹出对话框,但是显示此定制对话框的通常方法是不设置该对话框的可见性.对话框的父元素.我们需要使用PushModalAsync
显示它,并使用PopModalAsync
将其关闭.
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. We need to display it using PushModalAsync
and dismiss it using PopModalAsync
.
有关代码示例,您可以参考 PushModalAsync 或 PopModalAsync .
For code sample you can refer to PushModalAsync or PopModalAsync.
我不确定是什么原因阻止了您的UI导致导航延迟,因为您没有在对话框的后面张贴任何代码.无论如何,您可以尝试推送并弹出模式页面,看看是否有帮助.
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. Anyway, you can try to push and pop a modal page and see if this helps.
这篇关于Xamarin形式的导航延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!