ivandrofly

Untitled

Jul 5th, 2026
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. https://stackoverflow.com/questions/2884625/what-is-difference-between-and-auto-in-silverlight-grid-layout-definitio
  2.  
  3.  
  4. The key is that only the `*` rows participate in sharing the remaining space.
  5.  
  6. In your example:
  7.  
  8. ```xml
  9. <Grid.RowDefinitions>
  10. <RowDefinition Height="*" />
  11. <RowDefinition Height="2*" />
  12. <RowDefinition Height="3*" />
  13. <RowDefinition Height="Auto" />
  14. </Grid.RowDefinitions>
  15. ```
  16.  
  17. ### Step 1: Measure the `Auto` row
  18.  
  19. Suppose the grid is 600 pixels high, and the `Auto` row's content needs 120 pixels.
  20.  
  21. The `Auto` row gets exactly **120 px**.
  22.  
  23. Remaining height:
  24.  
  25. ```
  26. 600 - 120 = 480 px
  27. ```
  28.  
  29. ### Step 2: Add up the star weights
  30.  
  31. The remaining rows have weights:
  32.  
  33. * `*` = `1*`
  34. * `2*`
  35. * `3*`
  36.  
  37. Total weight:
  38.  
  39. ```
  40. 1 + 2 + 3 = 6
  41. ```
  42.  
  43. This is where the **6** comes from.
  44.  
  45. ### Step 3: Divide the remaining space
  46.  
  47. Each "star" represents one equal share:
  48.  
  49. ```
  50. 480 / 6 = 80 px per star
  51. ```
  52.  
  53. Now allocate according to the weights:
  54.  
  55. | Row | Weight | Fraction of remaining space | Height |
  56. | ---- | ------ | --------------------------- | ------ |
  57. | `*` | 1 | **1/6** | 80 px |
  58. | `2*` | 2 | **2/6 = 1/3** | 160 px |
  59. | `3*` | 3 | **3/6 = 1/2** | 240 px |
  60.  
  61. Notice that:
  62.  
  63. * First row: **1/6** because its weight is **1** out of a total of **6**.
  64. * Second row: **2/6 = 1/3**.
  65. * Third row: **3/6 = 1/2**.
  66.  
  67. The fractions add up to 1:
  68.  
  69. [
  70. \frac{1}{6}+\frac{2}{6}+\frac{3}{6}=\frac{6}{6}=1
  71. ]
  72.  
  73. So the first row gets **1/6** of the remaining height simply because its star weight is **1** and the total star weight is **6**. In general, a row with `N*` receives:
  74.  
  75. [
  76. \frac{N}{\text{sum of all star weights}}
  77. ]
  78.  
  79. of the space left after all `Auto` (and fixed-size) rows have been measured.
  80.  
Tags: C# wpf grid
Advertisement
Add Comment
Please, Sign In to add comment