public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow { DataContext = new MainWindowViewModel(), }; Main = desktop.MainWindow; } base.OnFrameworkInitializationCompleted(); }
public static void ActivateWorkaround(this Window window) { if (window is null) { throw new ArgumentNullException(nameof(window)); } // Call default Activate() anyway. window.Activate(); // Skip workaround for non-windows platforms. if (!IsWin32NT) { return; } var platformImpl = window.PlatformImpl; if (ReferenceEquals(platformImpl, null)) { return; } var platformHandle = platformImpl.Handle; if (ReferenceEquals(platformHandle, null)) { return; } var handle = platformHandle.Handle; if (IntPtr.Zero == handle) { return; } try { SetForegroundWindow(handle); } catch { // ignored } }
static void Main(string[] args) { var app = AppBuilder.Configure <App>() .LogToDebug(Avalonia.Logging.LogEventLevel.Verbose) .UsePlatformDetect() .SetupWithoutStarting() .Instance; var win = new Avalonia.Controls.Window(); var tb = new Avalonia.Controls.TextBlock { Text = "Hello World!" }; win.Content = tb; win.Show(); app.Run(win); }
/// <summary> /// 设置调整大小模式。 /// </summary> /// <param name="window"></param> /// <param name="value"></param> public static void SetResizeMode(this Window window, ResizeMode value) { var p = DI.Get <IDesktopPlatformService>(); switch (value) { case ResizeMode.NoResize: case ResizeMode.CanMinimize: window.CanResize = false; break; case ResizeMode.CanResize: #pragma warning disable CS0618 // 类型或成员已过时 case ResizeMode.CanResizeWithGrip: #pragma warning restore CS0618 // 类型或成员已过时 window.CanResize = true; break; } p.SetResizeMode(window.PlatformImpl.Handle.Handle, value); }
public static void SetDefaultFontFamily(this Window window) { if (DI.Platform == Platform.Windows) { if (HAS_FONT_MSYH) // (版权、许可)不能在非WinOS上使用 微软雅黑字体,不可将字体嵌入程序 { string name; var major = Environment.OSVersion.Version.Major; if (major > 6 || (major == 6 && Environment.OSVersion.Version.Minor >= 2)) { name = "Microsoft YaHei UI"; } else { name = "Microsoft YaHei"; } window.FontFamily = new FontFamily(name); } } }
/// <inheritdoc/> public ICredentials PromptGui(Application app, ICredentials knownCredentials) { var data = new MainWindowViewModel(); data.CredentialsCollected += CredentialsCollected; _window = new MainWindow { DataContext = data, }; app.Run(_window); if (!data.Success) { return(knownCredentials); } // do nothing rely on Git to prompt return(new Credentials(data.Username, knownCredentials.Protocol, knownCredentials.Host, knownCredentials.Path, data.Secret)); }
public static DeviceOrientation ToDeviceOrientation(this Avalonia.Controls.Window page) { return(page.Height > page.Width ? DeviceOrientation.Portrait : DeviceOrientation.Landscape); }
/* * [STAThread] * static void Main(string[] args) * { * Application.Init(); * var win = new Window(WindowType.Toplevel); * var button2 = new Button {Label = "HELLO"}; * button2.SetSizeRequest(100, 100); * * var button = new GLArea(); * //button.SetRequiredVersion(3, 2); * button.SetRequiredVersion(4, 0); * button.AutoRender = true; * button.Realized += (sender, eventArgs) => * { * Console.WriteLine("REALIZED"); * button.MakeCurrent(); * }; * button.Render += (e, args) => * { * Console.WriteLine("RENDER"); * args.Context.MakeCurrent(); * GL.glClearColor(.7f, .3f, 0, 1); * GL.glClear(GL.GL_COLOR_BUFFER_BIT); * GL.glFlush(); * GL.glFinish(); * //gtk_gl_swap_buffers(button.Handle); * //button.QueueRender(); * //GL.ClearColor(.3f, .3f, .3f, 1f); * //args.Context. * }; * button.SetSizeRequest(100, 100); * //button.Left = 10; * //button.Top = 10; * var fix = new Fixed {button, button2}; * fix.Move(button, 100, 100); * fix.Move(button2, 200, 100); * * var menu = new MenuBar(); * menu.Add(new MenuItem() {Label = "hello"}); * * fix.Add(menu); * win.Add(fix); * win.Hide(); * win.SetPosition(WindowPosition.Center); * win.ShowAll(); * win.Destroyed += (sender, eventArgs) => * { * Environment.Exit(0); * }; * button.QueueRender(); * Application.Run(); * * Console.WriteLine("Hello World!"); * } */ /* * public static void Main (string[] args) * { * Application.Init(); * Window win = new Window ("Menu Sample App"); * win.DeleteEvent += new DeleteEventHandler (delete_cb); * win.DefaultWidth = 200; * win.DefaultHeight = 150; * * VBox box = new VBox (false, 2); * * MenuBar mb = new MenuBar (); * Menu file_menu = new Menu (); * MenuItem exit_item = new MenuItem("Exit"); * exit_item.Activated += new EventHandler (exit_cb); * file_menu.Append (exit_item); * MenuItem file_item = new MenuItem("File"); * file_item.Submenu = file_menu; * mb.Append (file_item); * box.PackStart(mb, false, false, 0); * * Button btn = new Button ("Yep, that's a menu"); * box.PackStart(btn, true, true, 0); * * win.Add (box); * win.ShowAll (); * * Application.Run (); * } * * static void delete_cb (object o, DeleteEventArgs args) * { * Application.Quit (); * args.RetVal = true; * } * * static void exit_cb (object o, EventArgs args) * { * Application.Quit (); * } */ static public void Main(string[] args) { var window = new Window(); window.Show(); }
public OpenFileDialogService(Window owner) { _owner = owner; }