Slideable ListItem Control Using Images In UWP

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

  1. Introduction To Universal Windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015
  2. How to add UWP ToolKit controls in Universal Application Development With XAML AND C#

SlideableListItem control is a ContentControl, which provides the functionality for sliding left or right to expose functions. This effect can be forced to ignore the mouse, if only touch screen interaction is desired. This control can be used as a ListView Data Template root to create effects similar to those common in mobile Email apps like Outlook.

After reading this article, you will learn how to use UWP Tool Kit Control – SlideableListItem in Universal Windows apps development with XAML and Visual C#.

The important tools, given below 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.

Step 1

Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank app -> Give the suitable name for your app (UWPSlideableListItem)->OK.

Visual studio

Step 2

Choose target and minimum platform version for your Windows, that Universal Application will support. Afterwards, the project creates App.xaml and MainPage.xaml.

Visual studio

For adding UWPToolKit Control, please refer

Step 3

Add TextBlock control, change the name and text property for the title.

http://www.c-sharpcorner.com/article/adding-uwp-toolkit-controls-in-universal-application-development/

Step 4

Add XAML code, given below to create the data template for SlideableListItem control.
  1. <Page.Resources>  
  2.    <DataTemplate x:Key="ImageItemTemplate">  
  3.    </DataTemplate>  
  4. </Page.Resources>  
http://www.c-sharpcorner.com/article/adding-uwp-toolkit-controls-in-universal-application-development/

Step 5 

Add UWP Tool Kit Name Space in Mainpage.xaml.

xmlns:Controls="using:Microsoft.Toolkit.Uwp.UI.Controls"

Add SlideableListItem control from UWP Tool Kit and change the name property.

http://www.c-sharpcorner.com/article/adding-uwp-toolkit-controls-in-universal-application-development/

Step 6 

Add the images in the Assets folder, images for SlideableListItem.

http://www.c-sharpcorner.com/article/adding-uwp-toolkit-controls-in-universal-application-development/

Step 7 

Add XAML code, given below to create the data template for SlideableListItem control.
  1. <my:SlidableListItem x:Name="SLIItemtest" LeftIcon="Camera">  
  2.     <Grid Background="White">  
  3.         <Grid.ColumnDefinitions>  
  4.             <ColumnDefinition Width="50" />  
  5.             <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions>  
  6.         <Grid Grid.Column="0" Background="Cyan" x:Name="Checkmark">  
  7.             <SymbolIcon Symbol="Pictures" Foreground="White" /> </Grid>  
  8.         <Image Grid.Column="1" Source="{Binding IName}" Stretch="None"></Image>  
  9.     </Grid>  
  10. </my:SlidableListItem>  
<my:SlidableListItem x:Name="SLIItemtest" LeftIcon="Camera" /> <grid background= ">

Step 8 

Add List View control to list the images in SlideableListItem.

studio

Note 

Automatically, the code, given below will be generated in XAML code view, while we are finished in the design view.
  1. <Page xmlns:my="using:Microsoft.Toolkit.Uwp.UI.Controls" x:Class="UWPSlideListItem.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:UWPSlideListItem" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">  
  2.     <Page.Resources>  
  3.         <DataTemplate x:Key="ImageItemTemplate">  
  4.             <my:SlidableListItem x:Name="SLIItemtest" LeftIcon="Camera">  
  5.                 <Grid Background="White">  
  6.                     <Grid.ColumnDefinitions>  
  7.                         <ColumnDefinition Width="50" />  
  8.                         <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions>  
  9.                     <Grid Grid.Column="0" Background="Cyan" x:Name="Checkmark">  
  10.                         <SymbolIcon Symbol="Pictures" Foreground="White" /> </Grid>  
  11.                     <Image Grid.Column="1" Source="{Binding IName}" Stretch="None"></Image>  
  12.                 </Grid>  
  13.             </my:SlidableListItem>  
  14.         </DataTemplate>  
  15.     </Page.Resources>  
  16.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  17.         <TextBlock x:Name="tblTitle" HorizontalAlignment="Left" Margin="232,25,0,0" TextWrapping="Wrap" Text="Slidable List Item Test" VerticalAlignment="Top" FontWeight="Bold" FontSize="20" Width="226" />  
  18.         <ListView x:Name="lvSLI" SelectionMode="None" IsItemClickEnabled="False" HorizontalAlignment="Center" ItemsSource="{x:Bind Iitem, Mode=OneWay}" ItemTemplate="{StaticResource ImageItemTemplate}" Margin="159,81,98,34" Width="383">  
  19.             <ListView.ItemContainerStyle>  
  20.                 <Style TargetType="ListViewItem">  
  21.                     <Setter Property="HorizontalContentAlignment" Value="Stretch"/><Setter Property="Margin" Value="0,1"/>  
  22.                 </Style>  
  23.             </ListView.ItemContainerStyle>  
  24.         </ListView>  
  25.     </Grid>  
  26. </Page>  
Step 9 

Add the namespace and the code, given below in MainPage.xaml.cs
  1. using System.Collections.ObjectModel;  
  2. public class MenuItem {  
  3.     public string IName {  
  4.         get;  
  5.         set;  
  6.     }  
  7. }  
  8. public sealed partial class MainPage: Page {  
  9.     private readonly ObservableCollection < MenuItem > Iitem;  
  10.     public MainPage() {  
  11.         this.InitializeComponent();  
  12.         ObservableCollection < MenuItem > items = new ObservableCollection < MenuItem > ();  
  13.         for (int i = 0; i < 25; i++) {  
  14.             items.Add(new MenuItem() {  
  15.                 IName = "ms-appx:///Assets//img.jpg"  
  16.             });  
  17.         }  
  18.         Iitem = items;  
  19.     }  
  20. }  
  21. }  
studio

Step 10 

Deploy your app in the local machine and the output of UWPSlideableListItem app is given below.

studio

Left SlideableListItem output is given below.

studio

Right SlideableListItem output is given below.

studio

Summary

Now, you have successfully tested UWP Tool Kit – SlideableListItem control in Visual C# - UWP environment.


Similar Articles