November 24th, 2025
0 reactions

Why does XAML break down when I have an element that is half a billion pixels tall?

A customer reported that their program encountered rendering problems when they created elements that were a half billion pixels tall, and they wondered why this was happening.

A half billion pixels is an awful lot of pixels. At 96 pixels per inch, that gives you an element whose height is over 82 miles (132 km). There is no monitor that tall nor piece of paper that large.¹

The conceptual reason things break down with elements that large is that you have far exceeded any reasonable limits for element size. You have ventured into unexplored territory.

The practical reason that things break down is that XAML operates internally with single-precision IEEE floating point values. (For performance reasons, the internal calculations are performed only to single-precision accuracy even though the API surface exposes double-precision IEEE floating point. Attempts to revise the API to be less deceptive and expose the values as single-precision IEEE floating point values ran into compatibility problems.)

Single-precision IEEE floating point can represent exact integers up to approximately ±2²⁴ = ±16,777,216, and the customer’s 500,000,000-pixel-tall element is far beyond that. And even if the value could be represented exactly, the value is now so large that you have lost all fractional pixels, which will cause all sorts of rounding errors.

Since there is no screen large enough to display an entire 500,000,000-pixel tall element, you can shrink the element down to a size that is, say, only three times² the size of the user’s screen. If the user scrolls the viewport, you can adjust the element accordingly so that the visible portion of your virtual element remains realized.

¹ By some calculations, the largest possible PDF document is 381 km × 381 km. These calculations have, however, come into dispute.

² I chose “three times” because I believe that that is the factor used by XAML virtualizing control (like ListView) to determine the size of the realization window.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments