@@ -33,14 +33,21 @@ protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Si
33
33
var accumulatedSize = new Size ( 0 , 0 ) ;
34
34
_availableSize = availableSize ;
35
35
36
+ // Ensure we have a minimum size to prevent DivideByZeroException in WinUI
37
+ // When availableSize has zero dimensions, provide a minimal positive size for measurement
38
+ var measureSize = new Size (
39
+ Math . Max ( availableSize . Width , 1.0 ) ,
40
+ Math . Max ( availableSize . Height , 1.0 )
41
+ ) ;
42
+
36
43
var indexAfterEllipsis = GetFirstIndexToRender ( context ) ;
37
44
38
45
// Go through all items and measure them
39
46
for ( int index = 0 ; index < context . Children . Count ; index ++ )
40
47
{
41
48
if ( context . Children [ index ] is BreadcrumbBarItem breadcrumbItem )
42
49
{
43
- breadcrumbItem . Measure ( availableSize ) ;
50
+ breadcrumbItem . Measure ( measureSize ) ;
44
51
accumulatedSize . Width += index < indexAfterEllipsis ? 0 : breadcrumbItem . DesiredSize . Width ;
45
52
accumulatedSize . Height = Math . Max ( accumulatedSize . Height , breadcrumbItem . DesiredSize . Height ) ;
46
53
}
@@ -98,6 +105,10 @@ private int GetFirstIndexToRender(NonVirtualizingLayoutContext context)
98
105
var itemCount = context . Children . Count ;
99
106
var accumulatedWidth = 0d ;
100
107
108
+ // Handle zero or negative available width - hide all items
109
+ if ( _availableSize . Width <= 0 )
110
+ return itemCount ;
111
+
101
112
// Go through all items from the last item
102
113
for ( int index = itemCount - 1 ; index >= 0 ; index -- )
103
114
{
0 commit comments