@@ -13,7 +13,7 @@ public static class ListViewExtensions
13
13
private static readonly bool IsApiContract13Present = Windows . Foundation . Metadata . ApiInformation . IsApiContractPresent ( "Windows.Foundation.UniversalApiContract" , 13 ) ;
14
14
15
15
/// <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 .
17
17
/// </summary>
18
18
public static readonly DependencyProperty ItemCornerRadiusProperty = DependencyProperty . RegisterAttached (
19
19
"ItemCornerRadius" , typeof ( CornerRadius ) , typeof ( ListViewExtensions ) , new PropertyMetadata ( null , OnItemCornerRadiusPropertyChanged ) ) ;
@@ -39,7 +39,7 @@ public static void SetItemCornerRadius(ListViewBase element, CornerRadius value)
39
39
}
40
40
41
41
/// <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 .
43
43
/// </summary>
44
44
public static readonly DependencyProperty ItemMarginProperty = DependencyProperty . RegisterAttached (
45
45
"ItemMargin" , typeof ( Thickness ) , typeof ( ListViewExtensions ) , new PropertyMetadata ( null , OnItemMarginPropertyChanged ) ) ;
@@ -65,7 +65,7 @@ public static void SetItemMargin(ListViewBase element, Thickness value)
65
65
}
66
66
67
67
/// <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 .
69
69
/// </summary>
70
70
public static readonly DependencyProperty ItemMinHeightProperty = DependencyProperty . RegisterAttached (
71
71
"ItemMinHeight" , typeof ( double ) , typeof ( ListViewExtensions ) , new PropertyMetadata ( null , OnItemMinHeightPropertyChanged ) ) ;
@@ -173,26 +173,37 @@ private static void ItemMarginOnContainerContentChanging(ListViewBase sender, Co
173
173
if ( args . Phase > 0 || args . InRecycleQueue ) return ;
174
174
if ( ! IsApiContract13Present )
175
175
{
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.
179
179
args . ItemContainer . Margin = GetItemMargin ( sender ) ;
180
180
}
181
181
else
182
182
{
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' ,
184
184
// likely intended to visually separate items while adhering to the minimum
185
185
// touch target size guidelines of 40x40 effective pixels.
186
186
//
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)
195
193
//
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
196
207
var border = args . ItemContainer . FindDescendant < Border > ( ) ;
197
208
if ( border != null )
198
209
{
@@ -224,7 +235,8 @@ private static void ItemMinHeightOnContainerContentChanging(ListViewBase sender,
224
235
var margin = GetItemMargin ( sender ) ;
225
236
double offsetMargin = margin . Top + margin . Bottom ;
226
237
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.
228
240
args . ItemContainer . MinHeight = GetItemMinHeight ( sender ) - offsetMargin ;
229
241
}
230
242
else
0 commit comments