Skip to content

Commit ebe4b09

Browse files
committed
Exposed command alignment as property; Update internal alignments on property changed
1 parent 3786b84 commit ebe4b09

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/TabbedCommandBar/TabbedCommandBarItem.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,32 @@ public bool IsContextual
7171
new PropertyMetadata(HorizontalAlignment.Left));
7272

7373
/// <summary>
74-
/// Gets or sets a value indicating whether this tab is contextual.
74+
/// Gets or sets a value indicating the alignment of the command overflow button.
7575
/// </summary>
7676
public HorizontalAlignment OverflowButtonAlignment
7777
{
7878
get => (HorizontalAlignment)GetValue(OverflowButtonAlignmentProperty);
7979
set => SetValue(OverflowButtonAlignmentProperty, value);
8080
}
8181

82+
/// <summary>
83+
/// Identifies the <see cref="CommandAlignment"/> property.
84+
/// </summary>
85+
public static readonly DependencyProperty CommandAlignmentProperty = DependencyProperty.Register(
86+
nameof(CommandAlignment),
87+
typeof(HorizontalAlignment),
88+
typeof(TabbedCommandBarItem),
89+
new PropertyMetadata(HorizontalAlignment.Stretch));
90+
91+
/// <summary>
92+
/// Gets or sets a value indicating the alignment of the commands in the <see cref="TabbedCommandBarItem"/>.
93+
/// </summary>
94+
public HorizontalAlignment CommandAlignment
95+
{
96+
get => (HorizontalAlignment)GetValue(CommandAlignmentProperty);
97+
set => SetValue(CommandAlignmentProperty, value);
98+
}
99+
82100
/// <inheritdoc/>
83101
protected override void OnApplyTemplate()
84102
{
@@ -87,13 +105,21 @@ protected override void OnApplyTemplate()
87105
_primaryItemsControl = GetTemplateChild("PrimaryItemsControl") as ItemsControl;
88106
if (_primaryItemsControl != null)
89107
{
90-
_primaryItemsControl.HorizontalAlignment = HorizontalAlignment.Stretch;
108+
_primaryItemsControl.HorizontalAlignment = CommandAlignment;
109+
RegisterPropertyChangedCallback(CommandAlignmentProperty, (sender, dp) =>
110+
{
111+
_primaryItemsControl.HorizontalAlignment = (HorizontalAlignment)sender.GetValue(dp);
112+
});
91113
}
92114

93115
_moreButton = GetTemplateChild("MoreButton") as Button;
94116
if (_moreButton != null)
95117
{
96118
_moreButton.HorizontalAlignment = OverflowButtonAlignment;
119+
RegisterPropertyChangedCallback(OverflowButtonAlignmentProperty, (sender, dp) =>
120+
{
121+
_moreButton.HorizontalAlignment = (HorizontalAlignment)sender.GetValue(dp);
122+
});
97123
}
98124
}
99125
}

0 commit comments

Comments
 (0)