[英]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
。
對於代碼示例,您可以參考PushModalAsync或PopModalAsync 。
我不確定是什么阻止了您的 UI 導致導航延遲,因為您沒有在對話框后面發布任何代碼。 無論如何,您可以嘗試推送和彈出一個模態頁面,看看這是否有幫助。
由於表單在構建彈出窗口中沒有
請參閱此文檔頁面
https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/pop-ups/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.