How To Use Listview Control In Universal Application Development With XAML And C#

Before reading this article, please go through the article's link, given below:

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

The following important tools are required to develop UWP.

  1. Windows 10 (Recommended).
  2. Visual Studio 2015 Community Edition (It is a free software available online).

Now, we can discuss step by step app development.

Step1: Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank App -> Give the Suitable Name for your app (UWPListView) ->OK.

Blank App

Step 2: Choose the Target and minimum platform version your Windows Universal Application will support. Afterwards, the project creates App.xaml and MainPage.xaml.

version

Step 3: Open (double click) the file MainPage.xaml in the Solution Explorer and click the Toolbox tab on the left to open the list of Common XAML controls. Expand Common XAML Controls and drag the required control to the middle of the design canvas. 

Add TextBlock control, change the name and the text property, After draging  and dropping the ListView control, you have to change the Name property.

TextBlock control

You can add the following code to XAML -> <ListView x:Name="ListCountry" ......!..Add the code, given below:

  1. </ListView>  
  2. <x:String>India</x:String>  
  3. <x:String>Unites States</x:String>  
  4. <x:String>Sri Lanka</x:String>  
  5. <x:String>China</x:String>  
TextBlock control

Note: Automatically, the following code will be generated in XAML code view, while we are done in the design view.
  1. <Page x:Class="UWPListView.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UWPListView" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">  
  2.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  3.         <TextBlock x:Name="tbltitle" HorizontalAlignment="Left" Margin="117,39,0,0" TextWrapping="Wrap" Text="List View Test" VerticalAlignment="Top" Width="101" FontWeight="Bold" />  
  4.         <ListView x:Name="ListCountry" HorizontalAlignment="Left" Height="189" Margin="78,91,0,0" VerticalAlignment="Top" Width="171">  
  5.             <x:String>India</x:String>  
  6.             <x:String>Unites States</x:String>  
  7.             <x:String>Sri Lanka</x:String>  
  8.             <x:String>China</x:String>  
  9.         </ListView>  
  10.     </Grid>  
  11. </Page>  
Step 4: Deploy your app in local machine and the output of the UWPListView app on the local machine is given below:

Deploy

Summary: Now, you have successfully created and tested your ListView Control in Visual C# - UWP environment. 


Similar Articles