Inheritance: System.Windows.Window
コード例 #1
0
        private static void SystemMenuExecuted(object sender, ExecutedRoutedEventArgs args)
        {
            RibbonWindow rw = sender as RibbonWindow;

            if (rw != null)
            {
                // For right-clicks, display the system menu from the point of the mouse click.
                // For left-clicks, display the system menu in the top-left corner of the client area.
                Point devicePoint;
                MouseButtonEventArgs e = args.Parameter as MouseButtonEventArgs;
                if (e != null)
                {
                    // This is the right-click handler.  The presence of a MouseButtonEventArgs as args.Parameter
                    // indicates we are handling right-click.
                    devicePoint = rw.PointToScreen(e.GetPosition(rw));
                }
                else if (rw._clientAreaBorder != null)
                {
                    // This is the left-click handler.  We can only handle it correctly if the _clientAreaBorder
                    // template part is defined, because that is where we want to position the system menu.
                    devicePoint = rw._clientAreaBorder.PointToScreen(new Point(0, 0));
                }
                else
                {
                    // We can't handle this correctly, so exit.
                    return;
                }

                CompositionTarget compositionTarget = PresentationSource.FromVisual(rw).CompositionTarget;
                SystemCommands.ShowSystemMenu(rw, compositionTarget.TransformFromDevice.Transform(devicePoint));
                args.Handled = true;
            }
        }
コード例 #2
0
		/// <summary>
		///   Callback for mouse up, releases mouse capture and sends click notifications.
		/// </summary>
		/// <param name="e">The event data.</param>
		protected override void OnMouseUp(MouseButtonEventArgs e)
		{
			if (this.IsMouseCaptured)
			{
				this.ReleaseMouseCapture();
				if (IsMouseOver)
				{
					if (e.ChangedButton == MouseButton.Left && this.Ribbon != null)
					{
						// Selects the first tab in this contextual group.
						this.Ribbon.NotifyMouseClickedOnContextualTabGroup(this);
						e.Handled = true;
					}
					else if (e.ChangedButton == MouseButton.Right)
					{
						// Show SystemMenu
						RibbonWindow ribbonWindow = Window.GetWindow(this) as RibbonWindow;
						if (ribbonWindow != null)
						{
							if (SystemCommands.ShowSystemMenuCommand.CanExecute(null, ribbonWindow))
							{
								SystemCommands.ShowSystemMenuCommand.Execute( /*parameter*/ null, /* target*/ ribbonWindow);
								e.Handled = true;
							}
						}
					}
				}
			}

			base.OnMouseUp(e);
		}
コード例 #3
0
        private static void CloseApplicationExecuted(object sender, ExecutedRoutedEventArgs args)
        {
            RibbonWindow rw = sender as RibbonWindow;

            if (rw != null)
            {
                Application.Current.Shutdown();
                args.Handled = true;
            }
        }
コード例 #4
0
        private static void CloseWindowExecuted(object sender, ExecutedRoutedEventArgs args)
        {
            RibbonWindow rw = sender as RibbonWindow;

            if (rw != null)
            {
                SystemCommands.CloseWindow(rw);
                args.Handled = true;
            }
        }
コード例 #5
0
        private static void RestoreWindowCanExecute(object sender, CanExecuteRoutedEventArgs args)
        {
            RibbonWindow rw = sender as RibbonWindow;

            if (rw != null &&
                rw.WindowState != WindowState.Normal)
            {
                args.CanExecute = true;
            }
        }
コード例 #6
0
		/// <summary>
		///   Callback for mouse down.  Captures/Releases the mouse depending on whether
		///   the tab group was clicked.
		/// </summary>
		/// <param name="e">The event data.</param>
		protected override void OnMouseDown(MouseButtonEventArgs e)
		{
			if (e.ClickCount == 1 || e.ChangedButton == MouseButton.Right)
			{
				this.CaptureMouse();
				if (this.IsMouseCaptured)
				{
					// Though we have already checked this state, our call to CaptureMouse
					// could also end up changing the state, so we check it again.
					if (e.ButtonState != MouseButtonState.Pressed)
					{
						// Release capture since we decided not to press the button.
						this.ReleaseMouseCapture();
					}
				}
				e.Handled = true;
			}
			else if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left)
			{
				// On DoubleClick maximize/restore the window
				RibbonWindow ribbonWindow = Window.GetWindow(this) as RibbonWindow;
				if (ribbonWindow != null)
				{
					if (SystemCommands.MaximizeWindowCommand.CanExecute(null, ribbonWindow))
					{
						SystemCommands.MaximizeWindowCommand.Execute( /*parameter*/ null, /* target*/ ribbonWindow);
						e.Handled = true;
					}
					else if (SystemCommands.RestoreWindowCommand.CanExecute(null, ribbonWindow))
					{
						SystemCommands.RestoreWindowCommand.Execute(/*parameter*/ null, /* target*/ ribbonWindow);
						e.Handled = true;
					}
				}
			}

			base.OnMouseDown(e);
		}
コード例 #7
0
        private static void OnTitleChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonWindow rw = d as RibbonWindow;

            rw.OnTitleChanged(null);
        }