How To Use Semantic Zoom In Windows 10 UWP App

In Windows 10 using a Semantic Zoom control is a way to visualize a data set using different levels of meaning and easily switch between them. It effectively allows the user to use zoomout and zoomin view of the data by alphabetic grouping or summarizing the data in some way.

If you have a long list view then user can be able to jump particular to a item instead of continuing to scroll. For the user it can provide an easy and intuitive way to traverse the data with the higher groupings providing a shortcut into the list.

Let’s see the steps.

Create new Windows 10 UWP app and go to your design view.

  1. <SemanticZoom x:Name="semanticZoom" ScrollViewer.ZoomMode="Enabled">  
  2.   
  3.     <SemanticZoom.ZoomedOutView>  
  4.     </SemanticZoom.ZoomedOutView>  
  5.   
  6.     <SemanticZoom.ZoomedInView>  
  7.     </SemanticZoom.ZoomedInView>  
  8. </SemanticZoom>  
We need to enable the zooming.

List your items in inside the Zoomedinview and grouped item in zoomedoutview like the following code.
  1. <Page.DataContext>  
  2.     <local:MainViewModel></local:MainViewModel>  
  3. </Page.DataContext>  
  4. <Page.Resources>  
  5.     <CollectionViewSource x:Name="Collection" IsSourceGrouped="true" ItemsPath="Items" Source="{Binding Groups}" />  
  6. </Page.Resources>  
Add the view model and collection view source to get the list of data.

Set a GroupStyle using a GroupStyleSelector conditional logic.
  1. <SemanticZoom x:Name="semanticZoom" ScrollViewer.ZoomMode="Enabled">  
  2.     <SemanticZoom.ZoomedOutView>  
  3.         <ListView Margin="5">  
  4.             <ListView.ItemTemplate>  
  5.                 <DataTemplate>  
  6.                     <StackPanel Background="#FF3680D8">  
  7.                         <TextBlock Text="{Binding Group.Name }" Foreground="White" />  
  8.                     </StackPanel>  
  9.                 </DataTemplate>  
  10.             </ListView.ItemTemplate>  
  11.   
  12.         </ListView>  
  13.   
  14.     </SemanticZoom.ZoomedOutView>  
  15.     <SemanticZoom.ZoomedInView>  
  16.         <ListView ItemsSource="{Binding Source={StaticResource Collection}}">  
  17.             <ListView.ItemTemplate>  
  18.                 <DataTemplate>  
  19.                     <StackPanel>  
  20.                         <StackPanel Orientation="Horizontal">  
  21.                             <Grid Height="70" Margin="0,0,10,0" Width="370">  
  22.                                 <Grid.ColumnDefinitions>  
  23.                                     <ColumnDefinition Width="0.2*"></ColumnDefinition>  
  24.                                     <ColumnDefinition Width="0.8*"></ColumnDefinition>  
  25.                                 </Grid.ColumnDefinitions>  
  26.   
  27.                                 <TextBlock Grid.Column="1" Text="{Binding Title}" VerticalAlignment="Center" Foreground="Black" FontSize="20"></TextBlock>  
  28.                             </Grid>  
  29.                         </StackPanel>  
  30.                         <Line X1="0" Y1="2" X2="600" Y2="2" Stroke="Gray" StrokeThickness="1" Margin="0,0,0,5" Grid.ColumnSpan="3" VerticalAlignment="Bottom" />  
  31.                     </StackPanel>  
  32.                 </DataTemplate>  
  33.             </ListView.ItemTemplate>  
  34.             <ListView.GroupStyle>  
  35.                 <GroupStyle>  
  36.                     <GroupStyle.HeaderTemplate>  
  37.                         <DataTemplate>  
  38.                             <StackPanel Orientation="Vertical">  
  39.                                 <TextBlock Text='{Binding Name}' Foreground="Gray" FontSize="25" Margin="5" />  
  40.                             </StackPanel>  
  41.                         </DataTemplate>  
  42.                     </GroupStyle.HeaderTemplate>  
  43.                 </GroupStyle>  
  44.             </ListView.GroupStyle>  
  45.         </ListView>  
  46.     </SemanticZoom.ZoomedInView>  
  47. </SemanticZoom>  
Now go to your code behind page and write the following code.
  1. internal class SampleDataGroup   
  2. {  
  3.     public string Name   
  4.     {  
  5.         get;  
  6.         set;  
  7.     }  
  8.   
  9.     public List < SampleData > Items   
  10.     {  
  11.         get;  
  12.         set;  
  13.     }  
  14. }  
  15.   
  16. internal class SampleData   
  17. {  
  18.     public SampleData(string title)   
  19.     {  
  20.         Title = title;  
  21.     }  
  22.   
  23.     public string Title   
  24.     {  
  25.         get;  
  26.         private set;  
  27.     }  
  28. }  
  29.   
  30. internal class SampleDataGenerator   
  31. {  
  32.     private static List < SampleData > _data;  
  33.   
  34.     public static List < SampleDataGroup > GetGroupedData()   
  35.     {  
  36.         if (_data == null)  
  37.             GenerateData();  
  38.   
  39.         return _data.GroupBy(d => d.Title.Split(' ')[0],  
  40.             (key, items) => new SampleDataGroup()  
  41.             {  
  42.                 Name = key, Items = items.ToList()  
  43.             }).ToList();  
  44.     }  
List your data and grouped the items. Here I create dummy list of items.

Bind the items and also group header.
  1. private static void GenerateData()  
  2. {  
  3.     _data = new List < SampleData > ();  
  4.     _data.Add(new SampleData("A C#"));  
  5.     _data.Add(new SampleData("A XAML"));  
  6.     _data.Add(new SampleData("A Java"));  
  7.     _data.Add(new SampleData("A Windows"));  
  8.     _data.Add(new SampleData("A Android"));  
  9.     _data.Add(new SampleData("A 06"));  
  10.     _data.Add(new SampleData("A 07"));  
  11.   
  12.     _data.Add(new SampleData("B 01"));  
  13.     _data.Add(new SampleData("B 02"));  
  14.     _data.Add(new SampleData("B 03"));  
  15.     _data.Add(new SampleData("B 04"));  
  16.   
  17.     _data.Add(new SampleData("Item3 01"));  
  18.     _data.Add(new SampleData("Item3 02"));  
  19.     _data.Add(new SampleData("Item3 03"));  
  20.     _data.Add(new SampleData("Item3 04"));  
  21.     _data.Add(new SampleData("Item3 05"));  
  22.     _data.Add(new SampleData("Item3 06"));  
  23.   
  24.     _data.Add(new SampleData("Item3 01"));  
  25.     _data.Add(new SampleData("Item3 02"));  
  26.     _data.Add(new SampleData("Item3 03"));  
  27.     _data.Add(new SampleData("Item3 04"));  
  28.     _data.Add(new SampleData("Item3 05"));  
  29.     _data.Add(new SampleData("Item3 06"));  
  30.     _data.Add(new SampleData("Item3 07"));  
  31.     _data.Add(new SampleData("Item3 08"));  
  32.     _data.Add(new SampleData("Item3 09"));  
  33.     _data.Add(new SampleData("Item3 10"));  
  34.   
  35.     _data.Add(new SampleData("Group5 01"));  
  36.     _data.Add(new SampleData("Group5 02"));  
  37.     _data.Add(new SampleData("Group5 03"));  
  38.   
  39.   
  40.     _data.Add(new SampleData("Group6 01"));  
  41.     _data.Add(new SampleData("Group6 02"));  
  42.     _data.Add(new SampleData("Group6 03"));  
  43.   
  44.     _data.Add(new SampleData("Group7 01"));  
  45.     _data.Add(new SampleData("Group7 02"));  
  46.     _data.Add(new SampleData("Group7 03"));  
  47. }  
  48. }  
  49. protected override void OnNavigatedTo(NavigationEventArgs e)  
  50. {  
  51.     var collectionGroups = Collection.View.CollectionGroups;  
  52.     ((ListViewBase) this.semanticZoom.ZoomedOutView).ItemsSource = collectionGroups;  
  53. }  
Tapping any of the group headers takes you to the zoomed out view, then selecting a group jumps you back to the right item in the zoomed in view.

Now run the app and see the expected output like the following screen.

app

Source Code