/// <summary> /// Enables Eto.Forms support, builds and starts the host and waits for /// the main form of the specified type to close to shut down. /// <para> /// The Form type <typeparamref name="TForm"/> is added as a singleton /// service to the service provider if not already configured. /// </para> /// </summary> /// <typeparam name="TForm">The type of the main form class.</typeparam> /// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param> /// <param name="cancelToken">An optional <see cref="CancellationToken"/> that can be used to close the application.</param> public static void RunEtoForm <TForm>(this IHostBuilder hostBuilder, CancellationToken cancelToken = default) where TForm : Eto.Forms.Form { if (hostBuilder is null) { throw new ArgumentNullException(nameof(hostBuilder)); } var platform = Eto.Platform.Detect; using var application = new Eto.Forms.Application(platform); using var host = hostBuilder .ConfigureServices((_, services) => { services.AddEtoFormsHost(application); services.TryAddSingleton <TForm>(); services.Configure <EtoFormsOptions>(opts => opts.MainForm = typeof(TForm)); }) .Build(); host.Start(); var options = host.Services .GetRequiredService <IOptions <EtoFormsOptions> >().Value; object form = null; if (options.MainForm is Type formType) { form = ActivatorUtilities.GetServiceOrCreateInstance( host.Services, formType); } using var cancelReg = cancelToken.Register(obj => { var app = (Eto.Forms.Application)obj; app.Quit(); }, application); switch (form) { case Eto.Forms.Form mainForm: application.Run(mainForm); break; case Eto.Forms.Dialog dialog: application.Run(dialog); break; case null: application.Run(); break; } var hostLifetime = host.Services.GetRequiredService <IHostApplicationLifetime>(); hostLifetime.StopApplication(); host.WaitForShutdown(); }
public static void Main() { var platform = Eto.Platform.Detect; using var app = new Eto.Forms.Application(platform); using var form = new MainForm(); app.Run(form); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif // Attach new Eto.Forms application to running app var app = new Eto.Forms.Application(new Eto.WinRT.Platform()).Attach(); app.Run(); Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); //Associate the frame with a SuspensionManager key SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(ItemsPage), "AllGroups"); } // Ensure the current window is active Window.Current.Activate(); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="args">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; // Attach new Eto.Forms application to running app var app = new Eto.Forms.Application(new Eto.WinRT.Platform()).Attach(); app.Run(); // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); //Associate the frame with a SuspensionManager key SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(ItemsPage), "AllGroups")) { throw new Exception("Failed to create initial page"); } } // Ensure the current window is active Window.Current.Activate(); }
public static void Run(Form form) { _etoApplication.Run(form.EtoForm); }
public static void EtoStartup() { if (etoThread != null) { return; } // run Eto UI in separate thread etoThread = new Thread(new ThreadStart(() => { try { Eto.Platform etoPlatform = null; if (Environment.OSVersion.Platform == PlatformID.Win32NT && Type.GetType("Mono.Runtime") != null) { // Mono under Windows does not support WPF, which causes the // automatic platform detection to fail loading it. Skip the // detection and attempt to load the other platform assemblies // manually. string[] platformWinForms = Eto.Platforms.WinForms.Split(new char[] { ',' }); string[] platformGtk3 = Eto.Platforms.Gtk3.Split(new char[] { ',' }); string[] platformGtk2 = Eto.Platforms.Gtk2.Split(new char[] { ',' }); Tuple <string, string>[] platforms = new Tuple <string, string>[] { Tuple.Create(platformWinForms[0].Trim(), platformWinForms[1].Trim()), Tuple.Create(platformGtk3[0].Trim(), platformGtk3[1].Trim()), Tuple.Create(platformGtk2[0].Trim(), platformGtk2[1].Trim()) }; for (int i = 0; i < platforms.Length; i++) { try { string assemblyPath = Path.Combine(basePath, platforms[i].Item2 + ".dll"); Assembly assemblyWinForms = Assembly.LoadFile(assemblyPath); Type platformType = assemblyWinForms.GetType(platforms[i].Item1); etoPlatform = (Eto.Platform)Activator.CreateInstance(platformType); break; } catch (Exception e) { Log.Error("Eto: Failed to load platform " + platforms[i].Item1 + ": " + e.Message); } } } if (etoPlatform == null) { etoPlatform = Eto.Platform.Detect; } using (etoApplication = new Eto.Forms.Application(etoPlatform)) { etoApplication.Initialized += (s, e) => etoWaitHandle.Set(); etoApplication.Run(); } } catch { etoWaitHandle.Set(); throw; } })); etoThread.SetApartmentState(ApartmentState.STA); etoThread.Name = "EtoThread"; etoThread.IsBackground = true; etoThread.Start(); }
public void Run() { etoApplication.Run(mainForm.Form); renderLoopDispatcher.OnClosing(); }