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.
- Windows 10 (Recommended).
- 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:
- </ListView>
- <x:String>India</x:String>
- <x:String>Unites States</x:String>
- <x:String>Sri Lanka</x:String>
- <x:String>China</x:String>
Note: Automatically, the following code will be generated in XAML code view, while we are done in the design view.
- <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">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <TextBlock x:Name="tbltitle" HorizontalAlignment="Left" Margin="117,39,0,0" TextWrapping="Wrap" Text="List View Test" VerticalAlignment="Top" Width="101" FontWeight="Bold" />
- <ListView x:Name="ListCountry" HorizontalAlignment="Left" Height="189" Margin="78,91,0,0" VerticalAlignment="Top" Width="171">
- <x:String>India</x:String>
- <x:String>Unites States</x:String>
- <x:String>Sri Lanka</x:String>
- <x:String>China</x:String>
- </ListView>
- </Grid>
- </Page>
Step 4: Deploy your app in local machine and the output of the UWPListView app on the local machine is given below:
Summary: Now, you have successfully created and tested your ListView Control in Visual C# - UWP environment.