Skip to content

Commit 8f9692e

Browse files
committed
Fixed caption button padding in RTL and added FlowDirection inhereitance to window creation sample
1 parent 162d08f commit 8f9692e

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

components/TitleBar/samples/SamplePages/ShellPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page x:Class="TitleBarExperiment.Samples.ShellPage"
1+
<Page x:Class="TitleBarExperiment.Samples.ShellPage"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:controls="using:CommunityToolkit.WinUI.Controls"

components/TitleBar/samples/TitleBarFullSample.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
4444
{
4545
SystemBackdrop = new MicaBackdrop()
4646
};
47-
newWindow.Content = new ShellPage(newWindow);
47+
48+
// Create the content for the window to show
49+
// and set the FlowDirection to match the current region.
50+
newWindow.Content = new ShellPage(newWindow)
51+
{
52+
FlowDirection = this.FlowDirection
53+
};
54+
4855
newWindow.Activate();
4956
#endif
5057
}

components/TitleBar/src/TitleBar.WASDK.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace CommunityToolkit.WinUI.Controls;
1414

1515
[TemplatePart(Name = nameof(PART_FooterPresenter), Type = typeof(ContentPresenter))]
1616
[TemplatePart(Name = nameof(PART_ContentPresenter), Type = typeof(ContentPresenter))]
17-
1817
public partial class TitleBar : Control
1918
{
2019
WndProcHelper? WndProcHelper;
@@ -55,12 +54,23 @@ private void SetWASDKTitleBar()
5554
};
5655
}
5756

57+
// Set the caption buttons to match the flow direction of the titlebar
58+
UpdateCaptionButtonsDirection(this.FlowDirection);
59+
5860
PART_ContentPresenter = GetTemplateChild(nameof(PART_ContentPresenter)) as ContentPresenter;
5961
PART_FooterPresenter = GetTemplateChild(nameof(PART_FooterPresenter)) as ContentPresenter;
6062

6163
// Get caption button occlusion information.
6264
int CaptionButtonOcclusionWidthRight = Window.AppWindow.TitleBar.RightInset;
6365
int CaptionButtonOcclusionWidthLeft = Window.AppWindow.TitleBar.LeftInset;
66+
67+
// Swap left/right if in RTL mode
68+
if (this.FlowDirection == FlowDirection.RightToLeft)
69+
{
70+
(CaptionButtonOcclusionWidthRight, CaptionButtonOcclusionWidthLeft) = (CaptionButtonOcclusionWidthLeft, CaptionButtonOcclusionWidthRight);
71+
}
72+
73+
// Set padding columns to match caption button occlusion.
6474
PART_LeftPaddingColumn!.Width = new GridLength(CaptionButtonOcclusionWidthLeft);
6575
PART_RightPaddingColumn!.Width = new GridLength(CaptionButtonOcclusionWidthRight);
6676

@@ -101,9 +111,6 @@ private void UpdateCaptionButtons(FrameworkElement rootElement)
101111
Window.AppWindow.TitleBar.ButtonForegroundColor = Colors.Black;
102112
Window.AppWindow.TitleBar.ButtonInactiveForegroundColor = Colors.DarkGray;
103113
}
104-
105-
// Set the caption buttons to match the flow direction of the app
106-
UpdateCaptionButtonsDirection(rootElement.FlowDirection);
107114
}
108115

109116
private void UpdateCaptionButtonsDirection(FlowDirection direction)

0 commit comments

Comments
 (0)