title: Xamarin.Forms - Adjusting height of CollectionView to be minimum size to fit children
body: <p>I have a CollectionView with a few items in it. I'm trying to adjust the size of the CollectionView to be just big enough to fit all of its children. Right now, it's much larger than the amount of children it has.
  <a href="https://i.stack.imgur.com/kRg6Z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kRg6Z.png" alt="enter image description here" /></a></p>
  <p>The Blue color represents the size of the CollectionView. As you can see, it's well beyond the size of it's children. I'd like it to fit them perfectly, or at the very least be closer to the same size.</p>
  <p>I don't have any height requests on any of the elements on the page, including the CollectionView.</p>
  <p>Here's my code. It's not particularly pretty at the moment, but it's a work in progress.</p>
  <pre><code>&lt;StackLayout&gt;
                  &lt;CollectionView x:Name=&quot;assessmentsCollectionView&quot;
                                  BackgroundColor=&quot;Blue&quot;&gt;
                      &lt;CollectionView.ItemTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;StackLayout Spacing=&quot;10&quot;
                                           Padding=&quot;5&quot;&gt;
                                  &lt;Frame CornerRadius=&quot;5&quot;
                                         Padding=&quot;0&quot;
                                         HorizontalOptions=&quot;FillAndExpand&quot;
                                         VerticalOptions=&quot;FillAndExpand&quot;&gt;
                                      &lt;StackLayout Orientation=&quot;Horizontal&quot;&gt;
                                          &lt;Frame Padding=&quot;5&quot;
                                                 CornerRadius=&quot;0&quot;
                                                 WidthRequest=&quot;50&quot;&gt;
                                              &lt;Label Text=&quot;{Binding TypeLetter}&quot;
                                                     TextColor=&quot;#37474f&quot;
                                                     FontSize=&quot;24&quot;
                                                     VerticalTextAlignment=&quot;Center&quot;
                                                     HorizontalTextAlignment=&quot;Center&quot;/&gt;
                                          &lt;/Frame&gt;
                                          &lt;StackLayout Padding=&quot;10&quot;&gt;
                                              &lt;Label Text=&quot;{Binding Name}&quot;
                                                 TextColor=&quot;Black&quot;
                                                 FontSize=&quot;24&quot;/&gt;
                                              &lt;StackLayout Orientation=&quot;Horizontal&quot;&gt;
                                                  &lt;Image Source=&quot;calendarIcon.png&quot;
                                                         WidthRequest=&quot;12&quot;
                                                         HeightRequest=&quot;12&quot;/&gt;
                                                  &lt;Label Text=&quot;{Binding Date}&quot;
                                                         FontSize=&quot;12&quot;
                                                         TextColor=&quot;Gray&quot;/&gt;
                                              &lt;/StackLayout&gt;
                                          &lt;/StackLayout&gt;
                                      &lt;/StackLayout&gt;
                                  &lt;/Frame&gt;
                              &lt;/StackLayout&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/CollectionView.ItemTemplate&gt;
                  &lt;/CollectionView&gt;
              &lt;/StackLayout&gt;
  </code></pre>