Grid and StackPanel, which has the better performance?

后端 未结 1 455
遥遥无期
遥遥无期 2021-02-18 19:15

Let\'s read these codes, I\'ve defined two similar UserControls in a Windows Phone 8 project and I really want to which of them is better. I\'ve check the profiling, it seems th

相关标签:
1条回答
  • 2021-02-18 19:29

    You may be interested in the answers to this question: In what order are Panels the most efficient in terms of render time and performance?

    The short answer is it depends on how many children the panels have, and how those elements are sized and positioned. But in most cases, a StackPanel will be more efficient than a Grid as it has both a faster measure and arrangement pass.

    To quote from the accepted answer:

    Grid

    Defines a flexible grid area that consists of columns and rows.

    This can be the most performance intensive panel if proportional sizing or auto sizing is used. Calculating child item size can be a complex combination of the native size of the item and the layout specified by the grid. Layout is also the most complicated of all the panels. Slow to medium performance for the measure pass and slow to medium performance for the arrangement pass.

    StackPanel

    Arranges child elements into a single line that can be oriented horizontally or vertically.

    The StackPanel measures its children using either native or relative sizing in the opposite direction from its orientation and native sizing in the direction of its orientation (alignment does nothing in this direction). This makes it a mid-level performer in this area. The Arrangement pass is simply, just laying out the items in order. Probably the second-best performance for this pass. Medium performance for the measure pass and fast performance for the layout pass.

    Also in regards to memory consumption, both objects are different and take up different amounts of memory, and a Grid has RowDefinitions and ColumnDefinitions, so it actually contains more objects than your StackPanel

    0 讨论(0)
提交回复
热议问题