Skip to content

Commit 97b9dba

Browse files
committed
removed custom DP
1 parent dd49756 commit 97b9dba

File tree

2 files changed

+8
-43
lines changed

2 files changed

+8
-43
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/WrapPanel/WrapPanel.bind

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@
4646
<controls:WrapPanel Background="{ThemeResource Brush-Grey-04}"
4747
Padding="@[Padding:Thickness:0,0,0,0]@"
4848
VerticalSpacing="@[VerticalSpacing:Slider:5:0-200]@"
49-
HorizontalSpacing="@[HorizontalSpacing:Slider:5:0-200]@"
50-
VerticalContentAlignment="@[VerticalContentAlignment:Enum:VerticalAlignment.Top]@"
51-
HorizontalContentAlignment="@[HorizontalContentAlignment:Enum:HorizontalAlignment.Left]@" />
49+
HorizontalSpacing="@[HorizontalSpacing:Slider:5:0-200]@" />
5250
</ItemsPanelTemplate>
5351
</ItemsControl.ItemsPanel>
5452
<ListView.ItemContainerStyle>
5553
<Style TargetType="ListViewItem">
56-
<Setter Property="VerticalContentAlignment" Value="Stretch" />
57-
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
54+
<!-- Change those values to change the WrapPanel's children alignment -->
55+
<Setter Property="VerticalContentAlignment" Value="Center" />
56+
<Setter Property="HorizontalContentAlignment" Value="Center" />
5857
<Setter Property="Padding" Value="0" />
5958
<Setter Property="MinWidth" Value="0" />
6059
<Setter Property="MinHeight" Value="0" />

Microsoft.Toolkit.Uwp.UI.Controls/WrapPanel/WrapPanel.cs

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,42 +55,6 @@ public double VerticalSpacing
5555
typeof(WrapPanel),
5656
new PropertyMetadata(0d, LayoutPropertyChanged));
5757

58-
/// <summary>
59-
/// Gets or sets the vertical alignment to use when the control <see cref="Orientation"/> is set to <see cref="Orientation.Horizontal"/>.
60-
/// </summary>
61-
public VerticalAlignment VerticalContentAlignment
62-
{
63-
get => (VerticalAlignment)GetValue(VerticalContentAlignmentProperty);
64-
set => SetValue(VerticalContentAlignmentProperty, value);
65-
}
66-
67-
/// <summary>
68-
/// The DP to store the <see cref="VerticalContentAlignment"/> property value.
69-
/// </summary>
70-
public static readonly DependencyProperty VerticalContentAlignmentProperty = DependencyProperty.Register(
71-
nameof(VerticalContentAlignment),
72-
typeof(VerticalAlignment),
73-
typeof(WrapPanel),
74-
new PropertyMetadata(VerticalAlignment.Top, LayoutPropertyChanged));
75-
76-
/// <summary>
77-
/// Gets or sets the horizontal alignment to use when the control <see cref="Orientation"/> is set to <see cref="Orientation.Vertical"/>.
78-
/// </summary>
79-
public HorizontalAlignment HorizontalContentAlignment
80-
{
81-
get => (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty);
82-
set => SetValue(HorizontalContentAlignmentProperty, value);
83-
}
84-
85-
/// <summary>
86-
/// The DP to store the <see cref="HorizontalContentAlignment"/> property value.
87-
/// </summary>
88-
public static readonly DependencyProperty HorizontalContentAlignmentProperty = DependencyProperty.Register(
89-
nameof(HorizontalContentAlignment),
90-
typeof(HorizontalAlignment),
91-
typeof(WrapPanel),
92-
new PropertyMetadata(HorizontalAlignment.Left, LayoutPropertyChanged));
93-
9458
/// <summary>
9559
/// Gets or sets the orientation of the WrapPanel.
9660
/// Horizontal means that child controls will be added horizontally until the width of the panel is reached, then a new row is added to add new child controls.
@@ -301,11 +265,13 @@ void Arrange(UIElement child, bool isLast = false)
301265
UvRect arrangeRect;
302266
if (Orientation == Orientation.Horizontal)
303267
{
304-
arrangeRect = rect.WithVerticalAlignment(VerticalContentAlignment, row.Size.V);
268+
var verticalAlignment = (child as FrameworkElement)?.VerticalAlignment ?? VerticalAlignment.Top;
269+
arrangeRect = rect.WithVerticalAlignment(verticalAlignment, row.Size.V);
305270
}
306271
else
307272
{
308-
arrangeRect = rect.WithHorizontalAlignment(HorizontalContentAlignment, row.Size.V);
273+
var horizontalAlignment = (child as FrameworkElement)?.HorizontalAlignment ?? HorizontalAlignment.Left;
274+
arrangeRect = rect.WithHorizontalAlignment(horizontalAlignment, row.Size.V);
309275
}
310276

311277
var finalRect = arrangeRect.ToRect(Orientation);

0 commit comments

Comments
 (0)