C# Maui 將 ContentPage 的 ShowPopupAsync 函數獨立到 外部類別使用方法
C# Maui 將 ContentPage 的 ShowPopupAsync 函數獨立到 外部類別使用方法
GITHUB: https://github.com/jash-git/MAUI_WinAPI_Object_test/tree/main/Code/22
Code01 [MainPage]
private async void PopupBtn_Clicked(object sender, EventArgs e) { //await DisplayAlert("Alert", $"路徑:{AppDomain.CurrentDomain.BaseDirectory}", "OK");//await Class_Test.MainPagePoint = this; //await Class_Test.ShowPopup(); //int i=await CallShowPopup(); //if (await Class_Test.CallShowPopup()>100) if (await Class_Call.CallShowPopup() > 100) { labtime.IsVisible = !labtime.IsVisible;//元件隱藏/顯示 await DisplayAlert("Alert", $"{PopupBtn.CustomProperty};{PopupPage1.m_StrResult}", "OK");//await } } private async Task<int> CallShowPopup() { int intResult = 0; await Class_Test.ShowPopup(); return intResult; }
Code02 [Class_Test]
using CommunityToolkit.Maui.Views; using MAUI_WinAPI_Object_test.Views; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MAUI_WinAPI_Object_test { public class Class_Test { public static MainPage MainPagePoint = null; public static async Task ShowPopup() { await MainPagePoint.ShowPopupAsync(new PopupPage1());//this.ShowPopup(new PopupPage1()); await MainPagePoint.ShowPopupAsync(new GridPage()); } public static async Task<int> CallShowPopup() { int intResult = 110; await Class_Test.ShowPopup(); return intResult; } } }
Code03 [Class_Call]
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MAUI_WinAPI_Object_test { public class Class_Call { public static async Task<int> CallShowPopup() { int intResult = 110; await Class_Test.ShowPopup(); return intResult; } } }
One thought on “C# Maui 將 ContentPage 的 ShowPopupAsync 函數獨立到 外部類別使用方法”
非同步(async Task) 不可以使用ref/out 語法