Skip to content

Commit dcee180

Browse files
committed
minor list view extension comments tweaks
1 parent 6f2a953 commit dcee180

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

Screenbox/Extensions/ListViewExtensions.cs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class ListViewExtensions
1313
private static readonly bool IsApiContract13Present = Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 13);
1414

1515
/// <summary>
16-
/// Identifies the attached dependency property that specifies the <see cref="CornerRadius"/> for the items in a <see cref="ListViewBase"/>.
16+
/// Identifies the attached dependency property that specifies the <see cref="CornerRadius"/> of <see cref="ListViewBase"/> item.
1717
/// </summary>
1818
public static readonly DependencyProperty ItemCornerRadiusProperty = DependencyProperty.RegisterAttached(
1919
"ItemCornerRadius", typeof(CornerRadius), typeof(ListViewExtensions), new PropertyMetadata(null, OnItemCornerRadiusPropertyChanged));
@@ -39,7 +39,7 @@ public static void SetItemCornerRadius(ListViewBase element, CornerRadius value)
3939
}
4040

4141
/// <summary>
42-
/// Identifies the attached dependency property that specifies the margin between items in a <see cref="ListViewBase"/>.
42+
/// Identifies the attached dependency property that specifies the margin of the <see cref="ListViewBase"/> item.
4343
/// </summary>
4444
public static readonly DependencyProperty ItemMarginProperty = DependencyProperty.RegisterAttached(
4545
"ItemMargin", typeof(Thickness), typeof(ListViewExtensions), new PropertyMetadata(null, OnItemMarginPropertyChanged));
@@ -65,7 +65,7 @@ public static void SetItemMargin(ListViewBase element, Thickness value)
6565
}
6666

6767
/// <summary>
68-
/// Identifies the attached dependency property that specifies the minimum height for items in a <see cref="ListView"/>.
68+
/// Identifies the attached dependency property that specifies the minimum height of the <see cref="ListView"/> item.
6969
/// </summary>
7070
public static readonly DependencyProperty ItemMinHeightProperty = DependencyProperty.RegisterAttached(
7171
"ItemMinHeight", typeof(double), typeof(ListViewExtensions), new PropertyMetadata(null, OnItemMinHeightPropertyChanged));
@@ -173,26 +173,37 @@ private static void ItemMarginOnContainerContentChanging(ListViewBase sender, Co
173173
if (args.Phase > 0 || args.InRecycleQueue) return;
174174
if (!IsApiContract13Present)
175175
{
176-
// In Windows 10, the ListViewItemPresenter doesn't have an inner Border element,
177-
// resulting in the margin being applied at the ListViewItem container level.
178-
// This introduces an inactive hit-test region around the visual bounds of the item.
176+
// Due to the absence of a Border element in the Windows 10 ListViewItem,
177+
// margin must be set at the container level. This introduces an inactive
178+
// hit-test region around the visual bounds of the item.
179179
args.ItemContainer.Margin = GetItemMargin(sender);
180180
}
181181
else
182182
{
183-
// The ListViewItemPresenter in Windows 11 appears to have an inner Border element,
183+
// The ListViewItem in Windows 11 appears to have a Border element with a margin of '4,2,4,2',
184184
// likely intended to visually separate items while adhering to the minimum
185185
// touch target size guidelines of 40x40 effective pixels.
186186
//
187-
// __________________________
188-
// | Border 2px |
189-
// | ______________ |
190-
// | | 36px | |
191-
// | 4px | Content | 4px |
192-
// | |______________| |
193-
// | 2px |
194-
// |__________________________|
187+
// If the selection mode is set to single, multiple, or extended the item's visual tree looks like this:
188+
// ListViewItem
189+
// Root [ListViewItemPresenter]
190+
// Border (A border that specifies most of the layout and visual properties)
191+
// Content
192+
// Border (A selection indicator or CheckBox glyph)
195193
//
194+
// GridViewItem
195+
// Root [ListViewItemPresenter]
196+
// Border (A border that specifies most of the layout and visual properties
197+
// Content
198+
// Border (The CheckBox glyph)
199+
// Border (SelectedBorderBrush)
200+
// Border (SelectedInnerBorderBrush)
201+
//
202+
// When selection is disabled, then the item's visual tree looks like this:
203+
// ListViewItem
204+
// Root [ListViewItemPresenter]
205+
// Border (A border that specifies most of the layout and visual properties)
206+
// Content
196207
var border = args.ItemContainer.FindDescendant<Border>();
197208
if (border != null)
198209
{
@@ -224,7 +235,8 @@ private static void ItemMinHeightOnContainerContentChanging(ListViewBase sender,
224235
var margin = GetItemMargin(sender);
225236
double offsetMargin = margin.Top + margin.Bottom;
226237

227-
// Adjustment required to accommodate the added item container margin.
238+
// If a margin is applied to the container, we have to subtract the vertical values
239+
// from the minimum height to ensure it matches the Windows 11 ListViewItem dimensions.
228240
args.ItemContainer.MinHeight = GetItemMinHeight(sender) - offsetMargin;
229241
}
230242
else

0 commit comments

Comments
 (0)