c# - Xamarin Forms Multi-App - MacOS 项目未显示 Xamarin 表单
问题描述
编辑:添加到我创建的项目的链接: https ://drive.google.com/file/d/1A4XGKdxeC22_wqtNEtenLxYbgCp3I_dA/view?usp=sharing
我创建了一个非常基本的多平台应用程序 I Visual Studio 2019 (Windows 10) 有 4 个项目:Source Project Android iOS UWP
我按照以下说明添加了 MacOS 项目:
https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/other/mac
该应用程序编译但加载一个空白表单,并且不会按照 UWP、iOS 和 Android 应用程序显示任何 Xamarin 表单。
接下来,我在 Mac 上本地创建了一个空的 Multi-Platform 应用程序 - 按照上述说明添加 MacOS 并获得相同的结果,即加载空白表单。
我在 Mac 项目中使用的代码是上面的链接。
// AppDelelegate.cs
using AppKit;
using Foundation;
using Xamarin.Forms;
using Xamarin.Forms.Platform.MacOS;
using pbTrader;
namespace pbTrader.MacOS
{
[Register("AppDelegate")]
public class AppDelegate : FormsApplicationDelegate
{
NSWindow window;
public AppDelegate()
{
var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;
var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
window = new NSWindow(rect, style, NSBackingStore.Buffered, false);
window.Title = "Xamarin.Forms on Mac!"; // choose your own Title here
window.TitleVisibility = NSWindowTitleVisibility.Hidden;
}
public override NSWindow MainWindow
{
get { return window; }
}
public override void DidFinishLaunching(NSNotification notification)
{
Forms.Init();
LoadApplication(new App());
base.DidFinishLaunching(notification);
}
public override void WillTerminate(NSNotification notification)
{
// Insert code here to tear down your application
}
}
}
// Main.cs
using AppKit;
namespace pbTrader.MacOS
{
static class MainClass
{
static void Main(string[] args)
{
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate(); // add this line
NSApplication.Main(args);
}
}
}
解决方案
推荐阅读
- java - Logback - 自定义日志文件为空,如何配置记录器?
- authentication - 如何对来自核心托管 Blazor Web 程序集的图像 src 请求的用户进行身份验证
- c# - 如何在 Google Analytics Reporting API 中使用 OAuth2 进行身份验证?
- python - 关系“blog_comment”的“comment_id”列中的空值违反非空约束
- azure-functions - HTTP 触发的 Azure 函数的重试机制
- python - 二维矩阵中的插值
- reactjs - ReactJS Material UI 如何使用 DatePicker、LocalizationProvider、AdapterDateFns
- python - 在 python 中添加包含每个 JSON 数据的额外对象
- excel - 在 Excel 中添加最后一行更新的日期
- ms-access - 如何在另一个字段中标记一个字段中的重复值