internal static void EnableBlur(Window win) { // ウィンドウに半透明のアクリル効果を適用する var state = AcrylicWindow.GetAcrylicAccentState(win); SetBlur(win, state); if (!_internalStateTable.TryGetValue(win, out var _)) { var windowHelper = new WindowInteropHelper(win); var source = HwndSource.FromHwnd(windowHelper.Handle); source.AddHook(WndProc); // タイトルバーの各種ボタンで利用するコマンドの設定 var closeBinding = new CommandBinding(SystemCommands.CloseWindowCommand, (_, __) => { SystemCommands.CloseWindow(win); }); var minimizeBinding = new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, __) => { SystemCommands.MinimizeWindow(win); }); var maximizeBinding = new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, __) => { SystemCommands.MaximizeWindow(win); }); var restoreBinding = new CommandBinding(SystemCommands.RestoreWindowCommand, (_, __) => { SystemCommands.RestoreWindow(win); }); win.CommandBindings.Add(closeBinding); win.CommandBindings.Add(minimizeBinding); win.CommandBindings.Add(maximizeBinding); win.CommandBindings.Add(restoreBinding); var internalState = new AcrylicWindowInternalState() { RestoringState = WindowRestoringState.Default, CloseCommand = closeBinding, MinimizeCommand = minimizeBinding, MaximizeCommand = maximizeBinding, RestoreCommand = restoreBinding, }; _internalStateTable.Add(win, internalState); // フルスクリーン状態だったら、ウィンドウサイズの訂正をする if (win.WindowState == WindowState.Maximized) { FixMaximizedWindowSize(windowHelper.Handle); } // WPFのSizeToContentのバグ対策 // (WindowChrome使用時に、SizeToContentのウィンドウサイズ計算が正しく行われない) void onContentRendered(object sender, EventArgs e) { if (win.SizeToContent != SizeToContent.Manual) { win.InvalidateMeasure(); } win.ContentRendered -= onContentRendered; InvalidateRect(windowHelper.Handle, IntPtr.Zero, true); } win.ContentRendered += onContentRendered; InvalidateRect(windowHelper.Handle, IntPtr.Zero, true); } }
private CaptionButtonViewModel Create(CaptionButtonType type) { switch (type) { case CaptionButtonType.Close: return(CreateButton(type, PackIconKind.Close, "Close", () => SystemCommands.CloseWindow(_window))); case CaptionButtonType.Maximize: return(CreateButton(type, PackIconKind.WindowMaximize, "Maximize", () => SystemCommands.MaximizeWindow(_window))); case CaptionButtonType.Minimize: return(CreateButton(type, PackIconKind.WindowMinimize, "Minimize", () => SystemCommands.MinimizeWindow(_window))); case CaptionButtonType.Restore: return(CreateButton(type, PackIconKind.WindowRestore, "Restore", () => SystemCommands.RestoreWindow(_window))); case CaptionButtonType.EnterFullScreen: return(CreateButton(type, PackIconKind.Fullscreen, "Fullscreen", () => GoToState(AppWindowState.FullScreen))); case CaptionButtonType.ExitFullScreen: return(CreateButton(type, PackIconKind.FullscreenExit, "Exit fullscreen", () => GoToState(_stateBeforeFullscreen))); case CaptionButtonType.DockLeft: return(CreateButton(type, PackIconKind.ArrowCollapseLeft, "Dock left", () => DockLeft())); case CaptionButtonType.DockRight: return(CreateButton(type, PackIconKind.ArrowCollapseRight, "Dock right", () => DockRight())); case CaptionButtonType.CompactView: return(CreateButton(type, PackIconKind.Crop, "Compact View", () => GoToState(AppWindowState.Compact))); case CaptionButtonType.NormalView: return(CreateButton(type, PackIconKind.FilePresentationBox, "Normal View", () => GoToState(AppWindowState.Normal))); default: throw new Exception(); } }
/// <summary> /// 构造方法 /// </summary> public MercuriusWindow() { this.SetValue(Window.StyleProperty, Application.Current.Resources[typeof(MercuriusWindow)]); this.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (sender, e) => SystemCommands.CloseWindow(this))); this.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (sender, e) => SystemCommands.MaximizeWindow(this), (sender, e) => e.CanExecute = e.CanExecute = this.ResizeMode == ResizeMode.CanResize || this.ResizeMode == ResizeMode.CanResizeWithGrip)); this.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (sender, e) => SystemCommands.MinimizeWindow(this), (sender, e) => e.CanExecute = this.ResizeMode != ResizeMode.NoResize)); this.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (sender, e) => SystemCommands.RestoreWindow(this), (sender, e) => e.CanExecute = e.CanExecute = this.ResizeMode == ResizeMode.CanResize || this.ResizeMode == ResizeMode.CanResizeWithGrip)); }
private void OnMaximizeWindow(object target, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(this); }
protected void OnMaximizeExecute(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(this); }
private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(this); }
// Maximize private void CommandBinding_Executed_Maximize(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(this); isFullScreen = true; }
private void MaximizeWindow() { SystemCommands.MaximizeWindow(this.GetParentWindow()); }
/// <summary>The on system maximize window command.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> public void OnSystemMaximizeWindowCommand(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(this.Window); }
private void SetCommandBindings() { CommandBindings.AddRange(new[] { new CommandBinding(SystemCommands.MinimizeWindowCommand, (sender, e) => { SystemCommands.MinimizeWindow(this); }), new CommandBinding(SystemCommands.MaximizeWindowCommand, (sender, e) => { SystemCommands.MaximizeWindow(this); }), new CommandBinding(SystemCommands.RestoreWindowCommand, (sender, e) => { SystemCommands.RestoreWindow(this); }), new CommandBinding(SystemCommands.CloseWindowCommand, (sender, e) => { SystemCommands.CloseWindow(this); }), }); }
protected void MaximizeButtonClick(object sender, RoutedEventArgs e) { sender.ForWindowFromTemplate(w => SystemCommands.MaximizeWindow(w)); }
public MercuriusDialog() { this.SetValue(Window.StyleProperty, Application.Current.Resources[typeof(MercuriusDialog)]); this.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (sender, e) => SystemCommands.CloseWindow(this))); this.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (sender, e) => SystemCommands.MaximizeWindow(this), (sender, e) => e.CanExecute = e.CanExecute = this.ResizeMode == ResizeMode.CanResize || this.ResizeMode == ResizeMode.CanResizeWithGrip)); this.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (sender, e) => SystemCommands.MinimizeWindow(this), (sender, e) => e.CanExecute = this.ResizeMode != ResizeMode.NoResize)); this.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (sender, e) => SystemCommands.RestoreWindow(this), (sender, e) => e.CanExecute = e.CanExecute = this.ResizeMode == ResizeMode.CanResize || this.ResizeMode == ResizeMode.CanResizeWithGrip)); this.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (Application.Current != null && Application.Current.MainWindow != this) { this.Owner = Application.Current.MainWindow; } }
/// <summary> /// Maximizes the window, mimics the center button at the top of a normal window /// </summary> public static void MaximizeWindow(Window window) { SystemCommands.MaximizeWindow(window); }
private void MaximizeWindow() { SystemCommands.MaximizeWindow(this); ButtonMaxmize.Visibility = Visibility.Collapsed; ButtonRestore.Visibility = Visibility.Visible; }
public static void CommandBinding_Executed_Maximize(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow((Window)e.Parameter); }
/// <summary> /// Update the system control buttons in the window frame /// </summary> /// <param name="winMode">Window mode</param> private void UpdateWindowFrame(WindowMode winMode) { switch (winMode) { // Only close button should be visible if the mode is CanClose/PaneCanClose case WindowMode.CanClose: case WindowMode.PaneCanClose: if (minimizeButton != null) { minimizeButton.Visibility = Visibility.Collapsed; } if (maximizeButton != null) { maximizeButton.Visibility = Visibility.Collapsed; } if (restoreButton != null) { restoreButton.Visibility = Visibility.Collapsed; } break; // Only minimize and close buttons should be visible if the mode is Pane/CanMinimize case WindowMode.Pane: case WindowMode.CanMinimize: default: if (minimizeButton != null) { minimizeButton.Visibility = Visibility.Visible; Grid.SetColumn(minimizeButton, 2); } if (maximizeButton != null) { maximizeButton.Visibility = Visibility.Collapsed; } if (restoreButton != null) { restoreButton.Visibility = Visibility.Collapsed; } break; // All buttons - minimize, maximize and close will be visible if the mode is CanMaximize case WindowMode.CanMaximize: if (minimizeButton != null) { minimizeButton.Visibility = Visibility.Visible; Grid.SetColumn(minimizeButton, 1); } if (maximizeButton != null) { maximizeButton.Visibility = Visibility.Visible; } break; // All buttons - minimize, maximize and close will be hidden if the mode is CanMaximize case WindowMode.ChildWindow: if (minimizeButton != null) { minimizeButton.Visibility = Visibility.Collapsed; } if (maximizeButton != null) { maximizeButton.Visibility = Visibility.Collapsed; } if (restoreButton != null) { restoreButton.Visibility = Visibility.Collapsed; } if (closeButton != null) { closeButton.Visibility = Visibility.Collapsed; } break; } // If the mode is Pane/PaneCanClose then the window should be in maximized state if ((WindowFrameMode == WindowMode.Pane) || (WindowFrameMode == WindowMode.PaneCanClose)) { SystemCommands.MaximizeWindow(this); } }
internal static void EnableBlur(Window win) { var windowHelper = new WindowInteropHelper(win); // ウィンドウに半透明のアクリル効果を適用する AcrylicHelper.EnableBlur(windowHelper.Handle); // タイトルバーの各種ボタンで利用するコマンドの設定 win.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (_, __) => { SystemCommands.CloseWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, __) => { SystemCommands.MinimizeWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, __) => { SystemCommands.MaximizeWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, __) => { SystemCommands.RestoreWindow(win); })); }
internal static void EnableBlur(Window win) { var windowHelper = new WindowInteropHelper(win); // ウィンドウに半透明のアクリル効果を適用する AcrylicHelper.EnableBlur(windowHelper.Handle); // タイトルバーの各種ボタンで利用するコマンドの設定 win.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (_, __) => { SystemCommands.CloseWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, __) => { SystemCommands.MinimizeWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, __) => { SystemCommands.MaximizeWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, __) => { SystemCommands.RestoreWindow(win); })); // WPFのSizeToContentのバグ対策 // (WindowChrome使用時に、SizeToContentのウィンドウサイズ計算が正しく行われない) void onContentRendered(object sender, EventArgs e) { if (win.SizeToContent != SizeToContent.Manual) { win.InvalidateMeasure(); } win.ContentRendered -= onContentRendered; } win.ContentRendered += onContentRendered; }
private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(_window); e.Handled = true; }
internal static void EnableBlur(Window win) { var windowHelper = new WindowInteropHelper(win); var accent = new AccentPolicy(); var accentStructSize = Marshal.SizeOf(accent); // ウィンドウ背景のぼかしを行うのはWindows10の場合のみ accent.AccentState = IsWin10() ? AccentState.ACCENT_ENABLE_BLURBEHIND : AccentState.ACCENT_ENABLE_TRANSPARENTGRADIENT; accent.AccentFlags = 2; //accent.GradientColor = 0x99FFFFFF; // 60%の透明度が基本 accent.GradientColor = 0x00FFFFFF; // Tint Colorはここでは設定せず、Bindingで外部から変えられるようにXAML側のレイヤーとして定義 var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData(); data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; data.SizeOfData = accentStructSize; data.Data = accentPtr; SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); win.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (_, __) => { SystemCommands.CloseWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (_, __) => { SystemCommands.MinimizeWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (_, __) => { SystemCommands.MaximizeWindow(win); })); win.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (_, __) => { SystemCommands.RestoreWindow(win); })); }
private void MaxApp_Click(object sender, RoutedEventArgs e) { SystemCommands.MaximizeWindow(this); }
private void Fullscreen_Click(object sender, RoutedEventArgs e) { SystemCommands.MaximizeWindow(this); Fullscreen.Visibility = Visibility.Hidden; FullscreenExit.Visibility = Visibility.Visible; }
private void Button_Click_MaximizeWindow(object sender, RoutedEventArgs e) { SystemCommands.MaximizeWindow(this); }
public MainWindow() { this.CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, (command, executed) => SystemCommands.CloseWindow(this))); this.CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, (command, executed) => SystemCommands.MaximizeWindow(this), this.OnCanResizeWindow)); this.CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, (command, executed) => SystemCommands.MinimizeWindow(this), this.OnCanMinimizeWindow)); this.CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, (command, executed) => SystemCommands.RestoreWindow(this), this.OnCanResizeWindow)); List <ThemeModel> themes = new List <ThemeModel> { new ThemeModel { Uri = new Uri("/WpfDemoApp;component/Themes/PurpleTheme.xaml", UriKind.RelativeOrAbsolute), Label = "Purple Theme" }, new ThemeModel { Uri = new Uri("/WpfDemoApp;component/Themes/OrangeTheme.xaml", UriKind.RelativeOrAbsolute), Label = "Orange Theme" }, new ThemeModel { Uri = new Uri("/WpfDemoApp;component/Themes/BlueTheme.xaml", UriKind.RelativeOrAbsolute), Label = "Blue Theme" }, }; this.viewModel = new GlobalViewModel(themes); ICollectionView collectionView = CollectionViewSource.GetDefaultView(viewModel.themes); collectionView.CurrentChanged += collectionView_CurrentChanged; this.DataContext = viewModel; InitializeComponent(); }
private void MaximizeWindow() { SystemCommands.MaximizeWindow(this); }
// Maximize protected void CommandBinding_Executed_Maximize(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(this); }
private static void MaximizeWindowExecuted(object sender, ExecutedRoutedEventArgs e) { SystemCommands.MaximizeWindow(sender as Window); }