For clarity, I added a minimum width and color for each TitleBar element:
Тhis is what it looks like:
Problem 1
PART_RootGrid
has Padding.Right
causing the window button area to move to the right:
Fix
Set Padding="4,0,0,0"
for PART_RootGrid
:
https://github.com/WinUICommunity/WinUICommunity/blob/b959f0342c129db75d0370ac42c7f9ccf5c1bf5e/dev/Components/Controls/Labs/TitleBar/TitleBar.xaml#L21C33-L21C33
Problem 2
Due to PART_RootGrid.Padding.Left
regions are calculated incorrectly:
https://github.com/WinUICommunity/WinUICommunity/assets/136100876/148de3cd-9a70-49b5-a87a-a6f4ca2331e2
Fix
Fix SetDragRegionForCustomTitleBar method.
Plus (+) is draggable area, minus (-) is non-draggable area.
+[rootGrid.padding.left][leftPadding]
-[buttonsHolder]
+[icon][title][leftDrag]
-[content]
+[rightDrag]
-[footer]
+[rightPadding][rootGrid.padding.right]
I after applying fix, it will look like this:
https://github.com/WinUICommunity/WinUICommunity/assets/136100876/4637e586-82a4-4266-9553-ee1566b238b3
private void SetDragRegionForCustomTitleBar()
{
if (AutoConfigureCustomTitleBar && Window != null && PART_RightPaddingColumn != null && PART_LeftPaddingColumn != null)
{
double scaleAdjustment = GetScaleAdjustment();
PART_RightPaddingColumn.Width = new GridLength(Window.AppWindow.TitleBar.RightInset / scaleAdjustment);
PART_LeftPaddingColumn.Width = new GridLength(Window.AppWindow.TitleBar.LeftInset / scaleAdjustment);
var height = (int)(this.ActualHeight * scaleAdjustment);
Windows.Graphics.RectInt32 rect1 = new(0, 0, 0, height);
Windows.Graphics.RectInt32 rect2 = new(0, 0, 0, height);
Windows.Graphics.RectInt32 rect3 = new(0, 0, 0, height);
Windows.Graphics.RectInt32 rect4 = new(0, 0, 0, height);
rect1.X = 0;
rect1.Width = (int)((PART_RootGrid.Padding.Left
+ PART_LeftPaddingColumn.ActualWidth)
* scaleAdjustment);
rect2.X = rect1.X + rect1.Width + (int)((PART_ButtonsHolderColumn.ActualWidth) * scaleAdjustment);
rect2.Width = (int)((PART_IconColumn.ActualWidth
+ PART_TitleColumn.ActualWidth
+ PART_LeftDragColumn.ActualWidth)
* scaleAdjustment);
rect3.X = rect2.X + rect2.Width + (int)(PART_ContentColumn.ActualWidth * scaleAdjustment);
rect3.Width = (int)(PART_RightDragColumn.ActualWidth * scaleAdjustment);
rect4.X = rect3.X + rect3.Width + (int)((PART_FooterColumn.ActualWidth
+ PART_RightPaddingColumn.ActualWidth
+ PART_RootGrid.Padding.Right)
* scaleAdjustment);
rect4.Width = (int)(PART_RightPaddingColumn.ActualWidth * scaleAdjustment);
Windows.Graphics.RectInt32[] dragRects = new[] { rect1, rect2, rect3, rect4 };
Window.AppWindow.TitleBar.SetDragRectangles(dragRects);
}
}
Patch
Author: Dmitry Zhukovsky <[email protected]> 2023-11-04 17:51:03
Committer: Dmitry Zhukovsky <[email protected]> 2023-11-04 17:51:03
Parent: b959f0342c129db75d0370ac42c7f9ccf5c1bf5e (Fix #8 Tnx to @dzhukovsky)
Branch: main
Follows: v5.3.1
Precedes:
Fix drag regions calculation in the TitleBar control.
----------- dev/Components/Controls/Labs/TitleBar/TitleBar.WASDK.cs -----------
index 3d16fe6..b9b628a 100644
@@ -17,6 +17,7 @@ namespace WinUICommunity;
[TemplatePart(Name = nameof(PART_FooterColumn), Type = typeof(ColumnDefinition))]
[TemplatePart(Name = nameof(PART_RightDragColumn), Type = typeof(ColumnDefinition))]
[TemplatePart(Name = nameof(PART_TitleHolder), Type = typeof(StackPanel))]
+[TemplatePart(Name = nameof(PART_RootGrid), Type = typeof(Grid))]
public partial class TitleBar : Control
{
@@ -28,6 +29,7 @@ public partial class TitleBar : Control
ColumnDefinition? PART_FooterColumn;
ColumnDefinition? PART_RightDragColumn;
StackPanel? PART_TitleHolder;
+ Grid? PART_RootGrid;
private void SetWASDKTitleBar()
{
@@ -41,7 +43,7 @@ public partial class TitleBar : Control
Window.AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
ConfigPresenter();
-
+
this.Window.Activated -= Window_Activated;
this.Window.Activated += Window_Activated;
@@ -63,6 +65,7 @@ public partial class TitleBar : Control
PART_RightDragColumn = GetTemplateChild(nameof(PART_RightDragColumn)) as ColumnDefinition;
PART_FooterColumn = GetTemplateChild(nameof(PART_FooterColumn)) as ColumnDefinition;
PART_TitleHolder = GetTemplateChild(nameof(PART_TitleHolder)) as StackPanel;
+ PART_RootGrid = GetTemplateChild(nameof(PART_RootGrid)) as Grid;
// Get caption button occlusion information.
int CaptionButtonOcclusionWidthRight = Window.AppWindow.TitleBar.RightInset;
@@ -137,35 +140,33 @@ public partial class TitleBar : Control
PART_RightPaddingColumn.Width = new GridLength(Window.AppWindow.TitleBar.RightInset / scaleAdjustment);
PART_LeftPaddingColumn.Width = new GridLength(Window.AppWindow.TitleBar.LeftInset / scaleAdjustment);
- List<Windows.Graphics.RectInt32> dragRectsList = new();
-
- Windows.Graphics.RectInt32 dragRectL;
- dragRectL.X = (int)((PART_LeftPaddingColumn.ActualWidth
- + PART_ButtonsHolderColumn!.ActualWidth)
- * scaleAdjustment);
- dragRectL.Y = 0;
- dragRectL.Height = (int)(this.ActualHeight * scaleAdjustment);
- dragRectL.Width = (int)((PART_IconColumn!.ActualWidth
- + PART_TitleColumn!.ActualWidth
- + PART_LeftDragColumn!.ActualWidth)
+ var height = (int)(this.ActualHeight * scaleAdjustment);
+ Windows.Graphics.RectInt32 rect1 = new(0, 0, 0, height);
+ Windows.Graphics.RectInt32 rect2 = new(0, 0, 0, height);
+ Windows.Graphics.RectInt32 rect3 = new(0, 0, 0, height);
+ Windows.Graphics.RectInt32 rect4 = new(0, 0, 0, height);
+
+ rect1.X = 0;
+ rect1.Width = (int)((PART_RootGrid.Padding.Left
+ + PART_LeftPaddingColumn.ActualWidth)
* scaleAdjustment);
- dragRectsList.Add(dragRectL);
-
- Windows.Graphics.RectInt32 dragRectR;
- dragRectR.X = (int)((PART_LeftPaddingColumn.ActualWidth
- + PART_IconColumn.ActualWidth
- + PART_ButtonsHolderColumn!.ActualWidth
- + PART_TitleHolder!.ActualWidth
- + PART_LeftDragColumn.ActualWidth
- + PART_ContentColumn!.ActualWidth)
+
+ rect2.X = rect1.X + rect1.Width + (int)((PART_ButtonsHolderColumn.ActualWidth) * scaleAdjustment);
+ rect2.Width = (int)((PART_IconColumn.ActualWidth
+ + PART_TitleColumn.ActualWidth
+ + PART_LeftDragColumn.ActualWidth)
* scaleAdjustment);
- dragRectR.Y = 0;
- dragRectR.Height = (int)(this.ActualHeight * scaleAdjustment);
- dragRectR.Width = (int)(PART_RightDragColumn!.ActualWidth * scaleAdjustment);
- dragRectsList.Add(dragRectR);
- Windows.Graphics.RectInt32[] dragRects = dragRectsList.ToArray();
+ rect3.X = rect2.X + rect2.Width + (int)(PART_ContentColumn.ActualWidth * scaleAdjustment);
+ rect3.Width = (int)(PART_RightDragColumn.ActualWidth * scaleAdjustment);
+
+ rect4.X = rect3.X + rect3.Width + (int)((PART_FooterColumn.ActualWidth
+ + PART_RightPaddingColumn.ActualWidth
+ + PART_RootGrid.Padding.Right)
+ * scaleAdjustment);
+ rect4.Width = (int)(PART_RightPaddingColumn.ActualWidth * scaleAdjustment);
+ Windows.Graphics.RectInt32[] dragRects = new[] { rect1, rect2, rect3, rect4 };
Window.AppWindow.TitleBar.SetDragRectangles(dragRects);
}
}
------------- dev/Components/Controls/Labs/TitleBar/TitleBar.xaml -------------
index 61e01c5..983dad2 100644
@@ -18,7 +18,7 @@
<ControlTemplate TargetType="local:TitleBar">
<Grid x:Name="PART_RootGrid"
Height="{TemplateBinding MinHeight}"
- Padding="4,0,4,0"
+ Padding="4,0,0,0"
VerticalAlignment="Stretch"
Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
---------------------- dev/Components/Themes/Generic.xaml ----------------------
index 877fb1e..ae49b15 100644
@@ -2090,7 +2090,7 @@ Themes\Styles\TextBlock.xaml
<win:Setter Property="Template">
<win:Setter.Value>
<win:ControlTemplate TargetType="local:TitleBar">
- <win:Grid x:Name="PART_RootGrid" Height="{TemplateBinding MinHeight}" Padding="4,0,4,0" VerticalAlignment="Stretch" Background="{TemplateBinding Background}">
+ <win:Grid x:Name="PART_RootGrid" Height="{TemplateBinding MinHeight}" Padding="4,0,0,0" VerticalAlignment="Stretch" Background="{TemplateBinding Background}">
<win:Grid.ColumnDefinitions>
<win:ColumnDefinition x:Name="PART_LeftPaddingColumn" Width="0" />
<win:ColumnDefinition x:Name="PART_ButtonsHolderColumn" Width="Auto" />