How To Use HeaderedContentControl In UWP

The HeaderedContentControl is a UI control that allows content to be displayed with a specified header. The Header property can be any object and we can use the HeaderTemplate to specify a custom look to the header. Content for the HeaderedContentControl will align to the top left. This is to maintain the same functionality as the ContentControl.

HeaderedContent is from UWP Community Toolkit. The UWP Community Toolkit is a collection of helper functions, custom controls, and app services. It simplifies and demonstrates common developer tasks building UWP apps for Windows 10.

Reading this article, you can learn how to use HeaderedContent Control in Universal Windows Apps development with XAML and Visual C#.

The following important tools are required for developing UWP.

  1. Windows 10 (Recommended)
  2. Microsoft Visual Studio 2017
  3. Windows Anniversary Update (10.0.14393.0) or higher is needed to support correctly this feature.

Step 1

Open Visual studio 2017 -> Start -> New Project-> Select Windows Universal (under Visual C#)-> Blank App(Universal Windows) -> Give it a suitable name (UWPHeaderedContent)->OK.


After choosing the target and minimum platform version that your Windows Universal Application will support (Windows Anniversary Update (10.0.14393.0)), the project creates App.xaml and MainPage.xaml.


Step 2

Update the Reference, Microsoft.NETCore.UniversalWindowsPlatform with the latest version via Manage NuGet Packages.


Step 3

Add the following controls in the design window for HeaderedContentControl feature view. Add the StackPanel, TextBlock Control, and change the Name and Text property.


Add the HeaderedContentControl and Ellipse Control, inside the Stackpanel for Header content in shapes.

  1. <controls:HeaderedContentControl x:Name="HCCShape" Header="Shape Header content- Circle" HorizontalAlignment="Center" VerticalAlignment="Stretch" Height="120" >  
  2. <Ellipse x:Name="Shaellcir" Fill="LightPink" Height="100" Width="100" />  
  3. </controls:HeaderedContentControl>  

Add images to Assets folder for HeaderedContentControl Imagedemo.


Add the HeaderedContentControl and Image Control for Header content in image.

  1. <controls:HeaderedContentControl x:Name="HCCImage" Header="Image Header content- Nature" HorizontalAlignment="Center" VerticalAlignment="Stretch" Height="134" Width="213" >  
  2.    <Image x:Name="imgtest" Source="ms-appx:///Assets/img2.jpeg" Width="206"/>  
  3. </controls:HeaderedContentControl>  

Add the HeaderedContentControl and TextBlock and Image Control inside the RelativePanel for Header content in Message.

  1. <controls:HeaderedContentControl x:Name="HCCMsg" Header="RealtivePanel Header content- Messages" Margin="133,0,30,0">  
  2.     <RelativePanel HorizontalAlignment="Center" VerticalAlignment="Center">  
  3.         <Image x:Name="Icon" Height="50" Width="50" Source="ms-appx:///Assets/message.png" />  
  4.         <TextBlock x:Name="Msg" RelativePanel.RightOf="Icon" Text=" 5" />  
  5.         <TextBlock FontSize="12" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" RelativePanel.AlignLeftWith="Msg" RelativePanel.Below="Msg" Text="Unread" /> </RelativePanel>  
  6. </controls:HeaderedContentControl>  


Automatically, the following code will be generated in XAML code view, when we are done in the design view.

  1. <Page x:Class="UWPHeaderedContent.MainPage" xmlns="" xmlns:x="" xmlns:local="using:UWPHeaderedContent" xmlns:d="" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" xmlns:mc="" mc:Ignorable="d">  
  2.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  3.         <TextBlock x:Name="tblTitle" HorizontalAlignment="Left" Margin="400,65,0,0" TextWrapping="Wrap" Text="HeaderedContent XAML Control Demo" VerticalAlignment="Top" FontWeight="Bold" FontSize="36" Height="48" />  
  4.         <StackPanel Margin="387,140,433,4">  
  5.             <controls:HeaderedContentControl x:Name="HCCShape" Header="Shape Header content- Circle" HorizontalAlignment="Center" VerticalAlignment="Stretch" Height="120">  
  6.                 <Ellipse x:Name="Shaellcir" Fill="LightPink" Height="100" Width="100" /> </controls:HeaderedContentControl>  
  7.             <controls:HeaderedContentControl x:Name="HCCImage" Header="Image Header content- Nature" HorizontalAlignment="Center" VerticalAlignment="Stretch" Height="134" Width="213">  
  8.                 <Image x:Name="imgtest" Source="ms-appx:///Assets/img2.jpeg" Width="206" /> </controls:HeaderedContentControl>  
  9.             <controls:HeaderedContentControl x:Name="HCCMsg" Header="RealtivePanel Header content- Messages" Margin="133,0,30,0">  
  10.                 <RelativePanel HorizontalAlignment="Center" VerticalAlignment="Center">  
  11.                     <Image x:Name="Icon" Height="50" Width="50" Source="ms-appx:///Assets/message.png" />  
  12.                     <TextBlock x:Name="Msg" RelativePanel.RightOf="Icon" Text=" 5" />  
  13.                     <TextBlock FontSize="12" Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" RelativePanel.AlignLeftWith="Msg" RelativePanel.Below="Msg" Text="Unread" /> </RelativePanel>  
  14.             </controls:HeaderedContentControl>  
  15.         </StackPanel>  
  16.     </Grid>  
  17. </Page>  

Step 4

Deploy your App on a local machine. The output of the UWPHeaderedContent is,


Now, you have successfully tested HeaderedContent control in XAML and UWP environment using Visual Studio 2017.

Similar Articles