我試圖在我的本地Xamarin.Mac應用程式中嵌入一個用Xamarin.Forms創建的XAML頁面。并把這個視窗作為模態打開。但問題是,打開的視窗忽略了680х425的尺寸,而且打開后是非常小的正方形。我的問題出在哪里? 以下是我的代碼:
this. window = new NSWindow(new CGRect(new CGPoint(100, 100), new CGSize(680, 425)), NSWindowStyle。 Closable, NSBackingStore.Buffered, false)。)
PickInstallPath pickInstallPath = new();
this.window.ContentViewController = pickInstallPath.CreateViewController()。
NSApplication.SharedApplication.RunModalForWindow(this.window)。
P.S 如果我把設定ContentViewController的視窗以正常大小打開的那一行去掉。
uj5u.com熱心網友回復:
在本地專案中消費Xamarin.Forms ContentPage-derived頁面的程序如下:
添加Xamarin.Forms NuGet包到本地專案中。
添加ContentPage-derived頁面和任何依賴項到本地專案中。
呼叫Forms.Init方法。
構建 ContentPage-derived 頁面的實體,并使用以下擴展方法之一將其轉換為適當的本地型別:
CreateViewContainer(創建視圖)。
iOS 的 CreateViewController,Android 的 CreateSupportFragment,或 UWP 的 CreateFrameworkElement。 使用本地導航 API 導航到 ContentPage-derived 頁面的本地型別表示。
您可以參考本檔案以獲得更多資訊 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-forms
編輯: 你可能想在設定ContentViewController之后再呼叫SetFrame AFTER,因為視圖控制器的內容框架將覆寫視窗的設定框架。 或者你可以設定ViewController內容的框架,而完全不設定視窗的框架。 你可以添加這樣的代碼:
Window.ContentViewController.PreferredContentSize = size;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/320038.html
標籤:
