public static void ShowActivate(this Window window)
 {
     if (window.WindowState != WindowState.Normal)
     {
         window.WindowState = WindowState.Normal;
     }
     window.Activate();
 }
Пример #2
0
 /// <summary>
 /// Creates a thumbnail of the specified window.
 /// </summary>
 /// <param name="window">The window.</param>
 /// <param name="width">The width of the thumbnail.</param>
 /// <param name="path">The output path.</param>
 private static void CreateThumbnail(Avalonia.Controls.Window window, int width, string path)
 {
     var bitmap = ScreenCapture.Capture(
         (int)window.Bounds.TopLeft.X,
         (int)window.Bounds.TopLeft.Y,
         (int)window.Bounds.Width,
         (int)window.Bounds.Height);
     var newHeight = width * bitmap.Height / bitmap.Width;
 }
        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 (!OperatingSystem2.IsWindows)
            {
                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
            }
        }
        /// <summary>
        /// 设置调整大小模式。
        /// </summary>
        /// <param name="window"></param>
        /// <param name="value"></param>
        public static void SetResizeMode(this Window window, ResizeMode value)
        {
            var p = DI.Get <IPlatformService>();

            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);
        }