This commit is contained in:
Mahdi Hosseini 2023-11-05 13:56:58 +03:30
Родитель 0972be56e8
Коммит 8e84104a15
2 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -24,6 +24,7 @@ namespace CommunityToolkit.WinUI.Controls;
[TemplatePart(Name = PartPaneButton, Type = typeof(Button))]
[TemplatePart(Name = nameof(PART_LeftPaddingColumn), Type = typeof(ColumnDefinition))]
[TemplatePart(Name = nameof(PART_RightPaddingColumn), Type = typeof(ColumnDefinition))]
[TemplatePart(Name = nameof(PART_ButtonHolder), Type = typeof(StackPanel))]
public partial class TitleBar : Control
{
@ -64,6 +65,7 @@ public partial class TitleBar : Control
ColumnDefinition? PART_LeftPaddingColumn;
ColumnDefinition? PART_RightPaddingColumn;
StackPanel? PART_ButtonHolder;
public TitleBar()
{
@ -75,6 +77,7 @@ public partial class TitleBar : Control
PART_LeftPaddingColumn = GetTemplateChild(nameof(PART_LeftPaddingColumn)) as ColumnDefinition;
PART_RightPaddingColumn = GetTemplateChild(nameof(PART_RightPaddingColumn)) as ColumnDefinition;
Configure();
ConfigureButtonHolder();
if (GetTemplateChild(PartBackButton) is Button backButton)
{
backButton.Click -= BackButton_Click;
@ -124,6 +127,28 @@ public partial class TitleBar : Control
PaneButtonClick?.Invoke(this, new RoutedEventArgs());
}
private void ConfigureButtonHolder()
{
if (PART_ButtonHolder != null)
{
PART_ButtonHolder.SizeChanged -= PART_ButtonHolder_SizeChanged;
}
PART_ButtonHolder = GetTemplateChild(nameof(PART_ButtonHolder)) as StackPanel;
if(PART_ButtonHolder != null)
{
PART_ButtonHolder.SizeChanged += PART_ButtonHolder_SizeChanged;
}
}
private void PART_ButtonHolder_SizeChanged(object sender, SizeChangedEventArgs e)
{
#if WINAPPSDK
SetDragRegionForCustomTitleBar();
#endif
}
private void Configure()
{
#if WINDOWS_UWP && !HAS_UNO

Просмотреть файл

@ -165,7 +165,7 @@
Grid.Column="2"
Grid.ColumnSpan="6"
Background="Transparent" />
<StackPanel x:Name="ButtonHolder"
<StackPanel x:Name="PART_ButtonHolder"
Grid.Column="1"
Orientation="Horizontal">
<Button x:Name="PART_BackButton"