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

Before reading this article, please go through the following article.

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

The following important tools are required for developing 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 (FlipViewimage) -> OK.

 Blank App

Step 2: Choose the Target and Minimum platform version that your Windows Universal Application will support. After this, the project creates App.xaml and MainPage.xaml.

version

Step 3: Open (double click) the file MainPage.xaml in the Solution Explorer and click on 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 and change the name and text property.

TextBlock

After that, drag and drop the FlipView control, you have to change the name property .

TextBlock

Note: Automatically, the following code will be generated in XAML codeView, while we are done in the design View.

  1. <Page x:Class="Flipviewimage.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Flipviewimage" 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="261,34,0,0" TextWrapping="Wrap" Text="Flipview test" VerticalAlignment="Top" FontWeight="Bold" Width="100" />    
  4.         <FlipView x:Name="FVtest" HorizontalAlignment="Left" Margin="77,83,0,0" VerticalAlignment="Top" Width="496" Height="226" /> </Grid>    
  5. </Page>    
Step 4 : In MainPage.Xaml remove the “/” in FlipView tag,

FlipView

Step 5 : In MainPage.Xaml, insert the following code to FlipView tag.
  1. <FlipView.ItemTemplate>  
  2.     <DataTemplate>  
  3.         <Grid>  
  4.             <Image Source="{Binding}" Stretch="UniformToFill" /> </Grid>  
  5.     </DataTemplate>  
  6. </FlipView.ItemTemplate>  
  7. </FlipView>  
Finally, the entire MainPage.Xaml code looks like,
  1. <Page x:Class="Flipviewimage.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Flipviewimage" 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="261,34,0,0" TextWrapping="Wrap" Text="Flipview test" VerticalAlignment="Top" FontWeight="Bold" Width="100" />  
  4.         <FlipView x:Name="FVtest" HorizontalAlignment="Left" Margin="77,83,0,0" VerticalAlignment="Top" Width="496" Height="226">  
  5.             <FlipView.ItemTemplate>  
  6.                 <DataTemplate>  
  7.                     <Grid>  
  8.                         <Image Source="{Binding}" Stretch="UniformToFill" /> </Grid>  
  9.                 </DataTemplate>  
  10.             </FlipView.ItemTemplate>  
  11.         </FlipView>  
  12.     </Grid>  
  13. </Page>  
Step 6: Create new folder in your project as Images and add some images to Images Folder

Create new folder

Step 7: Add the following code in constructor method (MainPage() method) in MainPage.xaml.cs. This code is used for setting the image resource path for FlipView control,
  1. String path = Directory.GetCurrentDirectory() + @"\Images";  
  2. FVtest.ItemsSource = Directory.GetFiles(path).Select(p => "ms-appx:///" + p);  
code

Step 8: Deploy your App in Local Machine, and the output of the FlipViewtest App is,

output

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

 

Up Next
    Ebook Download
    View all
    Learn
    View all