Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let TitleBar show 'SystemMenu' on mouse right button up. #627

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
private const string ElementRestoreButton = "PART_RestoreButton";
private const string ElementCloseButton = "PART_CloseButton";

private static DpiScale? dpiScale;

private DependencyObject? parentWindow;

#region Static properties

/// <summary>
Expand Down Expand Up @@ -423,6 +427,8 @@
{
SetValue(TemplateButtonCommandProperty, new RelayCommand<TitleBarButtonType>(OnTemplateButtonClick));

dpiScale ??= VisualTreeHelper.GetDpi(this);

Loaded += OnLoaded;
Unloaded += OnUnloaded;
}
Expand Down Expand Up @@ -465,6 +471,15 @@
{
base.OnApplyTemplate();

parentWindow = VisualTreeHelper.GetParent(this);

while (parentWindow != null && parentWindow is not Window)
{
parentWindow = VisualTreeHelper.GetParent(parentWindow);
}

this.MouseRightButtonUp += TitleBar_MouseRightButtonUp;

_mainGrid = GetTemplateChild<System.Windows.Controls.Grid>(ElementMainGrid);
_icon = GetTemplateChild<System.Windows.Controls.ContentPresenter>(ElementIcon);

Expand Down Expand Up @@ -652,6 +667,15 @@
}
}

/// <summary>
/// Show 'SystemMenu' on mouse right button up.
/// </summary>
private void TitleBar_MouseRightButtonUp(object sender, MouseButtonEventArgs e)

Check failure on line 673 in src/Wpf.Ui/Controls/TitleBar/TitleBar.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'MouseButtonEventArgs' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 673 in src/Wpf.Ui/Controls/TitleBar/TitleBar.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'MouseButtonEventArgs' could not be found (are you missing a using directive or an assembly reference?)
{
var point = PointToScreen(e.GetPosition(this));
SystemCommands.ShowSystemMenu(parentWindow as Window, new Point(point.X / dpiScale.Value.DpiScaleX, point.Y / dpiScale.Value.DpiScaleY));
}

private T GetTemplateChild<T>(string name)
where T : DependencyObject
{
Expand Down
Loading