EmbedSample.Browser.cs 1004 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using Avalonia;
  3. using Avalonia.Platform;
  4. using Avalonia.Web.Blazor;
  5. using ControlCatalog.Pages;
  6. using Microsoft.JSInterop;
  7. namespace ControlCatalog.Web;
  8. public class EmbedSampleWeb : INativeDemoControl
  9. {
  10. public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
  11. {
  12. var runtime = AvaloniaLocator.Current.GetRequiredService<IJSInProcessRuntime>();
  13. if (isSecond)
  14. {
  15. var iframe = runtime.Invoke<IJSInProcessObjectReference>("document.createElement", "iframe");
  16. iframe.InvokeVoid("setAttribute", "src", "https://www.youtube.com/embed/kZCIporjJ70");
  17. return new JSObjectControlHandle(iframe);
  18. }
  19. else
  20. {
  21. // window.createAppButton source is defined in "app.js" file.
  22. var button = runtime.Invoke<IJSInProcessObjectReference>("window.createAppButton");
  23. return new JSObjectControlHandle(button);
  24. }
  25. }
  26. }