public void UnregisterWindowUsingAttachedProperty()
        {
            // ARRANGE
            var window = new Window();
            window.SetValue(DialogServiceViews.IsRegisteredProperty, true);
            
            // ACT
            window.SetValue(DialogServiceViews.IsRegisteredProperty, false);

            // ASSERT
            Assert.That(DialogServiceViews.Views, Is.Empty);
        }
        /// <summary>
        /// 开始进入全屏模式
        /// 进入全屏模式后,窗口可通过 API 方式(也可以用 Win + Shift + Left/Right)移动,调整大小,但会根据目标矩形寻找显示器重新调整到全屏状态。
        /// 进入全屏后,不要修改样式等窗口属性,在退出时,会恢复到进入前的状态
        /// 进入全屏模式后会禁用 DWM 过渡动画
        /// </summary>
        public static void StartFullScreen(System.Windows.Window window)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window), $"{nameof(window)} 不能为 null");
            }

            //确保不在全屏模式
            if (window.GetValue(BeforeFullScreenWindowPlacementProperty) == null &&
                window.GetValue(BeforeFullScreenWindowStyleProperty) == null)
            {
                var hwnd = new WindowInteropHelper(window).EnsureHandle();
                var hwndSource = HwndSource.FromHwnd(hwnd);

                //获取当前窗口的位置大小状态并保存
                var placement = InteropMethods.GetWindowPlacement(hwnd);
                window.SetValue(BeforeFullScreenWindowPlacementProperty, placement);

                //修改窗口样式
                var style = (InteropValues.WindowStyles) InteropMethods.GetWindowLongPtr(hwnd, InteropValues.GWL_STYLE);
                window.SetValue(BeforeFullScreenWindowStyleProperty, style);
                //将窗口恢复到还原模式,在有标题栏的情况下最大化模式下无法全屏,
                //这里采用还原,不修改标题栏的方式
                //在退出全屏时,窗口原有的状态会恢复
                //去掉WS_THICKFRAME,在有该样式的情况下不能全屏
                //去掉WS_MAXIMIZEBOX,禁用最大化,如果最大化会退出全屏
                //去掉WS_MAXIMIZE,使窗口变成还原状态,不使用ShowWindow(hwnd, ShowWindowCommands.SW_RESTORE),避免看到窗口变成还原状态这一过程(也避免影响窗口的Visible状态)
                style &= ~(InteropValues.WindowStyles.WS_THICKFRAME | InteropValues.WindowStyles.WS_MAXIMIZEBOX | InteropValues.WindowStyles.WS_MAXIMIZE);
                InteropMethods.SetWindowLong(hwnd, InteropValues.GWL_STYLE, (IntPtr) style);

                //禁用 DWM 过渡动画 忽略返回值,若DWM关闭不做处理
                InteropMethods.DwmSetWindowAttribute(hwnd, InteropValues.DwmWindowAttribute.DWMWA_TRANSITIONS_FORCEDISABLED, 1,
                    sizeof(int));

                //添加Hook,在窗口尺寸位置等要发生变化时,确保全屏
                hwndSource.AddHook(KeepFullScreenHook);

                if (InteropMethods.GetWindowRect(hwnd, out var rect))
                {
                    //不能用 placement 的坐标,placement是工作区坐标,不是屏幕坐标。

                    //使用窗口当前的矩形调用下设置窗口位置和尺寸的方法,让Hook来进行调整窗口位置和尺寸到全屏模式
                    InteropMethods.SetWindowPos(hwnd, (IntPtr) InteropValues.HWND_TOP, rect.Left, rect.Top, rect.Width,
                        rect.Height, (int) InteropValues.WindowPositionFlags.SWP_NOZORDER);
                }
            }
        }
		private static void DettachWindowListeners(Window window, object vm) {
			if(vm != null) {
				var listener = (WindowMessageListener)window.GetValue(WindowMessageListenerProperty);
				if(listener != null) {
					window.SetValue(WindowMessageListenerProperty, null);
					listener.Dettach(vm, window);
				}
			}
		}
		private static void AttachWindowListeners(Window window, object vm) {
			if(vm != null) {
				var listener = new WindowMessageListener(window);
				window.SetValue(WindowMessageListenerProperty, listener);
				listener.Attach(vm, window);

				window.DataContextChanged += window_DataContextChanged;
			}
		}
Example #5
0
        public bool capture(String path)
        {
            try
            {
                Thread newWindowThread = new Thread(new ThreadStart(() =>
                {
                    // Create and show the Window
                    mainWindow = new Window();
                    this.path = path;
                    this.makeDir();
                    Rectangle resolution = Screen.PrimaryScreen.Bounds;

                    mainWindow.WindowState = WindowState.Maximized;
                    mainWindow.WindowStyle = WindowStyle.None;
                    mainWindow.BorderThickness = new Thickness(0);
                    mainWindow.SizeToContent = SizeToContent.WidthAndHeight;

                    //mainWindow.SetValue() = new ScaleTransform()

                    mainWindow.SetValue(Window.LayoutTransformProperty, null);

                    //Generate Canvas
                    canvas = new Canvas();
                    canvas.Width = resolution.Width;
                    canvas.Height = resolution.Height;
                    canvas.Background = getImageBrush();

                    mainWindow.Content = canvas;
                    mainWindow.MouseDown += new System.Windows.Input.MouseButtonEventHandler(mouseDown);
                    mainWindow.MouseMove += new System.Windows.Input.MouseEventHandler(mouseMove);
                    mainWindow.MouseUp += new System.Windows.Input.MouseButtonEventHandler(mouseUp);

                    // always on top
                    mainWindow.Topmost = true;
                    mainWindow.Show();
                    // Start the Dispatcher Processing
                    System.Windows.Threading.Dispatcher.Run();
                }));

                newWindowThread.SetApartmentState(ApartmentState.STA);
                // Make the thread a background thread
                newWindowThread.IsBackground = true;
                // Start the thread
                newWindowThread.Start();

                CaptureTool.captureResetEvent.WaitOne();
            }
            catch(Exception)
            {

            }
            return true;
        }
        private static HotkeyServiceHelper EnsureHotkeyServiceHelper(Window window)
        {
            HotkeyServiceHelper helper = (HotkeyServiceHelper)window.GetValue(HotkeyServiceHelperPropertyKey.DependencyProperty);

            if (helper == null)
            {
                helper = new HotkeyServiceHelper(window);
                window.SetValue(HotkeyServiceHelperPropertyKey, helper);
            }

            return helper;
        }
Example #7
0
        private static WindowExtensions _EnsureAttachedExtensions(Window window)
        {
            Assert.IsNotNull(window);

            var ext = (WindowExtensions)window.GetValue(WindowExtensionsProperty);
            if (ext == null)
            {
                ext = new WindowExtensions(window);
                window.SetValue(WindowExtensionsProperty, ext);
            }

            return ext;
        }
 private static void SetPinned(Window window, bool value)
 {
     var interopHelper = new WindowInteropHelper(window);
     var handle = interopHelper.Handle;
     if (handle == IntPtr.Zero)
     {
         window.SetValue(IsPinnedProperty, value);
         window.Loaded += WindowLoaded;
         return;
     }
     if (value)
         PinToDesktop(handle);
     else
         UnpinFromDesktop(handle);
 }
        public void RegisterWindowUsingAttachedProperty()
        {
            // ARRANGE
            var window = new Window();

            var expected = new[]
            {
                new ViewWrapper(window)
            };

            // ACT
            window.SetValue(DialogServiceViews.IsRegisteredProperty, true);
            
            // ASSERT
            Assert.That(DialogServiceViews.Views, Is.EqualTo(expected));
        }
 public static void SetCloseCondition(Window obj, bool value)
 {
     obj.SetValue(CloseConditionProperty, value);
 }
Example #11
0
 public static void SetIsModalProperty(Window window, bool value)
 {
     window.SetValue(IsModalProperty, value);
 }
Example #12
0
 public static void SetMessageBoxResult(System.Windows.Window target, bool?value)
 {
     target.SetValue(MessageBoxResultProperty, value);
 }
Example #13
0
 internal static void SetIsClosingAsPartOfDragOperation(Window element, bool value)
 {
     element.SetValue(IsClosingAsPartOfDragOperationProperty, value);
 }
Example #14
0
 public static void SetInstance(Window window, WindowChrome value)
 {
     window.SetValue(InstanceProperty, value);
 }
Example #15
0
        /// <summary>
        /// Makes sure the view is a window is is wrapped by one.
        /// </summary>
        /// <param name="model">The view model.</param>
        /// <param name="view">The view.</param>
        /// <param name="isDialog">Whethor or not the window is being shown as a dialog.</param>
        /// <returns>The window.</returns>
        protected virtual Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as Window;

            if (window == null) {
                window = new Window {
                    Content = view,
                    SizeToContent = SizeToContent.WidthAndHeight
                };

                window.SetValue(View.IsGeneratedProperty, true);

                var owner = InferOwnerOf(window);
                if (owner != null)
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    window.Owner = owner;
                }
                else
                {
                    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            else
            {
                var owner = InferOwnerOf(window);
                if (owner != null && isDialog)
                    window.Owner = owner;
            }

            return window;
        }
 public static void SetIsEnabled(Window window, bool value) {
     window.SetValue(IsEnabledProperty, value);
 }
Example #17
0
      /// <summary>Gets the behaviors.
      /// </summary>
      /// <param name="window">The window.</param>
      /// <returns></returns>
      
      private static WindowBehaviors GetInternalBehaviors(Window window)
      {
         if (window == null)
         {
            throw new ArgumentNullException("window");
         }

         var behaviors = (WindowBehaviors)window.GetValue(BehaviorsProperty);

         if(behaviors == null)
         {
            behaviors = new WindowBehaviors { Window = window };
            window.SetValue(BehaviorsProperty, behaviors);
         }
         else if(behaviors.Window != null)
         {
            behaviors.Window = window;
            window.SetValue(BehaviorsProperty, behaviors);
         }

         return behaviors;
      }
Example #18
0
 public static void SetHideCloseButton(Window obj, bool value)
 {
     obj.SetValue(HideCloseButtonProperty, value);
 }
Example #19
0
 private static void SetIsHiddenCloseButton(Window obj, bool value)
 {
     obj.SetValue(IsHiddenCloseButtonKey, value);
 }
Example #20
0
 private static void SetCurrentValidatedControl (Window d, FrameworkElement value)
 {
     d.SetValue(CurrentValidatedControlProperty, value);
 }
Example #21
0
 private static void SetTooltipPopup (Window d, TooltipPopup value)
 {
     d.SetValue(TooltipPopupProperty, value);
 }
Example #22
0
 public static void SetApplicationBar([NotNull] System.Windows.Window obj, ApplicationBar value)
 {
     ValidationHelper.NotNull(obj, "obj");
     obj.SetValue(ApplicationBarProperty, value);
 }
 /// <summary>
 ///     Sets the value of the WindowMovement.IsDraggable attached property on a Window.
 /// </summary>
 /// <param name="window">The Window to set the property on.</param>
 /// <param name="value">The value to set the property to.</param>
 public static void SetIsDraggable(Window window, bool value)
 {
     window.SetValue(IsDraggableProperty, value);
 }
Example #24
0
 /// <summary>
 /// Sets the extra content on the caption area.
 /// </summary>
 /// <param name="window">The object.</param>
 /// <param name="value">The value.</param>
 public static void SetCaptionExtraContent(Window window, object value)
 {
     if (window == null) { throw new ArgumentNullException("window"); }
     window.SetValue(CaptionExtraContentProperty, value);
 }
 public static void SetSettings(Window element, Settings value)
 {
     element.SetValue(SettingsProperty, value);
 }
Example #26
0
 public static void SetHasMaximizeButton(Window element, bool value)
 {
     element.SetValue(ControlBox.HasMaximizeButtonProperty, value);
 }
Example #27
0
 public static void SetRemoveIcon(Ctrl target, bool value)
 {
     target.SetValue(RemoveIconProperty, value);
 }
Example #28
0
 public static void SetDialogResult(Ctrl target, bool?value)
 {
     target.SetValue(DialogResultProperty, value);
 }
Example #29
0
 public static void SetDialogResult(Window target, bool? value)
 {
     target.SetValue(DialogResultProperty, value);
 }
Example #30
0
 public static void SetDisableControls(System.Windows.Window wnd, bool value) => wnd.SetValue(DisableControlsProperty, value);
Example #31
0
 public static void SetWindowChrome(Window window, WindowChrome chrome)
 {
     Verify.IsNotNull(window, "window");
     window.SetValue(WindowChromeProperty, chrome);
 }
Example #32
0
 public static void SetIsMainWindow([NotNull] System.Windows.Window obj, bool value)
 {
     ValidationHelper.NotNull(obj, "obj");
     obj.SetValue(IsMainWindowProperty, BooleanBoxingHelper.Box(value));
 }
Example #33
0
 /// <summary>Sets the behaviors.
 /// </summary>
 /// <param name="window">The window.</param>
 /// <param name="chrome">The chrome.</param>
 public static void SetBehaviors(Window window, WindowBehaviors chrome)
 {
    if (window == null)
    {
       throw new ArgumentNullException("window");
    }
    window.SetValue(BehaviorsProperty, chrome);
 }
Example #34
0
 public static void SetDialogResult(WindowControl target, bool?value)
 => target.SetValue(DialogResultProperty, value);
Example #35
0
 public static void SetChrome(Window window, Chrome chrome)
 {
     if (window == null) { throw new ArgumentNullException("window"); }
     window.SetValue(Chrome.ChromeProperty, chrome);
 }
Example #36
0
 public static void SetFixMaximize(Window ribbonWindow, bool value)
 {
     ribbonWindow.SetValue(FixMaximizeProperty, value);
 }
 public static void SetHasMinimizeButton(Window element, bool value)
 {
     element.SetValue(HasMinimizeButtonProperty, value);
 }
 public static void SetCloseWindow(Window window, bool value)
 {
     window.SetValue(CloseWindowProperty, value);
 }