1
0

EmbedSample.Mac.cs 799 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using Avalonia.Platform;
  3. using Avalonia.Threading;
  4. using ControlCatalog.Pages;
  5. using MonoMac.Foundation;
  6. using MonoMac.WebKit;
  7. namespace ControlCatalog.Desktop;
  8. public class EmbedSampleMac : INativeDemoControl
  9. {
  10. public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
  11. {
  12. // Note: We are using MonoMac for example purposes
  13. // It shouldn't be used in production apps
  14. MacHelper.EnsureInitialized();
  15. var webView = new WebView();
  16. Dispatcher.UIThread.Post(() =>
  17. {
  18. webView.MainFrame.LoadRequest(new NSUrlRequest(new NSUrl(
  19. isSecond ? "https://bing.com" : "https://google.com/")));
  20. });
  21. return new MacOSViewHandle(webView);
  22. }
  23. }