A Foldable Content Control For UWP

One of the last projects which I did was coding the design of an enterprise app. Like in most Enterprise apps, this app had a list, which needs to be folded and expanded but unfortunately, there was no such out of the box control in UWP (like we had in WPF). Thus, I had to create a one from scratch. With the time limitation in mind, I decided to go with a user control. The final outcome was not too bad. Hence, I decided to share it with the community.
 
 
 
Properties 
 
You can use this control with any kind of framework element. It’s not just limited to a list. What you have to do is simply assign the property ‘FoldableContent’ to the content you want, as shown below. 
  1. <controls:FoldableContentControl.FoldableContent>  
  2.                     <ListView ItemsSource="{x:Bind MyItemList}">  
  3.                         <ListView.ItemTemplate>  
  4.                             <DataTemplate>  
  5.                                 <StackPanel BorderBrush="LightGray"  
  6.                                         BorderThickness="0.5">  
  7.                                     <TextBlock Text="{Binding}"  
  8.                                            HorizontalAlignment="Center"  
  9.                                            Padding="10"/>  
  10.                                 </StackPanel>  
  11.                             </DataTemplate>  
  12.                         </ListView.ItemTemplate>  
  13.                         <ListView.ItemContainerStyle>  
  14.                             <Style TargetType="ListViewItem">  
  15.                                 <Setter Property="HorizontalContentAlignment" Value="Stretch" />  
  16.                                 <Setter  Property="Padding" Value="0"/>  
  17.                             </Style>  
  18.                         </ListView.ItemContainerStyle>  
  19.                     </ListView>  
  20.                 </controls:FoldableContentControl.FoldableContent>   

You can specify the content in the header from changing the ‘HeaderText’ property.

You can specify the content, which you want to display, when there are no items in the content. Simply, add a framework element to the ‘EmptyContent’ property or change the ‘EmptyText’ property. To display this emptiness, you have to set the ‘DisplayEmpty’ property to true. (If a ItemsControl simply binds the ‘Count’ property with a value converter).

You can find the source code in my GitHub repo.