-
|
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
It is the same code as in MS sample https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=wasdk#interactive-content |
Beta Was this translation helpful? Give feedback.
-
|
@DarranRowe Thanks. public static void SetNonClientRegionElementsOnTitleBar(this Window Window, FrameworkElement Element, params FrameworkElement[] ExceptElements)
{
if (ExceptElements.Contains(Element))
{
throw new ArgumentException($"\"{nameof(ExceptElements)}\" contains the \"{nameof(Element)}\" which is not allowed", nameof(Element));
}
float DpiScaleFactor = User32.GetDpiScaleFactorFromWindow(Window.GetWindowHandle());
if (DpiScaleFactor > 0)
{
Point ElementPoint = Element.TransformToVisual(Window.Content).TransformPoint(new Point(0, 0));
RectInt32 DraggableRect = new RectInt32((int)(ElementPoint.X * DpiScaleFactor), (int)(ElementPoint.Y * DpiScaleFactor), (int)(Element.ActualWidth * DpiScaleFactor), (int)(Element.ActualHeight * DpiScaleFactor));
if (InputNonClientPointerSource.GetForWindowId(Window.AppWindow.Id) is InputNonClientPointerSource NonClientSource)
{
NonClientSource.ClearRegionRects(NonClientRegionKind.Caption);
NonClientSource.SetRegionRects(NonClientRegionKind.Caption, new RectInt32[] { DraggableRect });
if (ExceptElements.Length > 0)
{
List<RectInt32> ExceptRects = new List<RectInt32>(ExceptElements.Length);
foreach (FrameworkElement ExceptElement in ExceptElements)
{
Point ExceptElementPoint = ExceptElement.TransformToVisual(Window.Content).TransformPoint(new Point(0, 0));
ExceptRects.Add(new RectInt32((int)(ExceptElementPoint.X * DpiScaleFactor), (int)(ExceptElementPoint.Y * DpiScaleFactor), (int)(ExceptElement.ActualWidth * DpiScaleFactor), (int)(ExceptElement.ActualHeight * DpiScaleFactor)));
}
NonClientSource.ClearRegionRects(NonClientRegionKind.Passthrough);
NonClientSource.SetRegionRects(NonClientRegionKind.Passthrough, ExceptRects.Distinct().ToArray());
}
}
}
} |
Beta Was this translation helpful? Give feedback.
@DarranRowe Thanks.
Here is the code that helps set the NonClient region using
InputNonClientPointerSource. Please correct me if any misunderstanding.Hope the code could help someone who seeking the solution on
InputNonClientPointerSource