WindowsPhone 8.1: Now UniversalWrapPanel is an Alternative For WrapPanel

Introduction

I am still really addicted to "WrapPanel" because WrapPanel is great for laying out things in a vertical or horizontal orientation until you reach the edge of the container and then move to the next column or row. But unfortunately I found "WrapPanel" is no longer supported by Windows Store apps (Universal Apps). Yestereday I discovered that "UniversalWrapPanel" is an alternative for "WrapPanel" layout. And I heartily say thanks very much to @gregstoll for making UniversalWrapPanel. In this article I will explain UniversalWrapPanel.

Building the sample

  • Ensure you've downloaded and installed the Windows Phone SDK. For more information, see Get the SDK.

  • I assume that you're going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you need to take some additional steps. For more info, see Register your Windows Phone device for development.

  • This article assumes you're using Microsoft Visual Studio Express 2013 for Windows.

Description

Previously in Windows Phone 8.0, the WrapPanel control is available from Microsoft.Phone.Controls. Toolkit.dll. WrapPanel is a good layout for positioning child elements sequentially from left to right or top to bottom. When elements extend beyond the panel edge, they are positioned in the next row or column. Unfortunately now WrapPanel is not supported by Windows Store apps so we need an alternative for "WrapPanel" in Windows Store apps (UniversalWrapPanel). Ok, all right, let's start to understand the new control with the following procedure.

Step 1

  • Open Visual Studio 2013
  • Create a new project (for example: "WrapPanel8.1")

Install UniversalWrapPanel for Windows Phone 8.1, run the following command in the Package Manager Console:

PM> Install-Package UniversalWrapPanel

You will then find the "UniversalWrapPanel" DLL in the references like this.

wrap Panel

Step 2

Open MainPage.xaml and add the namespace to the XAML:

  1. xmlns:UniversalWrapPanel="using:Gregstoll"   
Step 3

Let's write the following XAML code to use UniversalWrapPanel.
  1.   <Grid Background="#FF59ABB4">    
  2.           <Grid.RowDefinitions>    
  3.               <RowDefinition Height="Auto"/>    
  4.               <RowDefinition Height="Auto"/>    
  5.               <RowDefinition Height="Auto"/>    
  6.               <RowDefinition Height="Auto"/>    
  7.           </Grid.RowDefinitions>    
  8.           <TextBlock FontSize="25" Text="Horizontal UniversalWrapPanel:"/>    
  9.           <!--Horizontal Panel-->    
  10.          <UniversalWrapPanel:UniversalWrapPanel Grid.Row="1" Orientation="Horizontal" Background="#FF34AC21">    
  11.              <Button Content="Button1" />    
  12.              <Button Content="Button2" />    
  13.              <Button Content="Button3" />    
  14.              <Button Content="Button4" />    
  15.              <Button Content="Button5" />    
  16.          </UniversalWrapPanel:UniversalWrapPanel>    
  17.          <TextBlock FontSize="25" Grid.Row="2" Text="Vertical UniversalWrapPanel:"/>    
  18.          <!--Vertical Panel-->    
  19.          <UniversalWrapPanel:UniversalWrapPanel Background="#FFC500FF" Grid.Row="3" Orientation="Vertical">    
  20.              <Button Content="Button1" />    
  21.              <Button Content="Button2" />    
  22.              <Button Content="Button3" />    
  23.              <Button Content="Button4" />    
  24.              <Button Content="Button5" />    
  25.          </UniversalWrapPanel:UniversalWrapPanel>    
  26.      </Grid>   
ScreenShots:

vertical universal wrap panel

Summary

From this article we have learned how to use UniversalWrapPanel in Windows Phone 8.1. And I hope you don't need the source code file from me, because the necessary code is available in this article.

This article is also available in my original blog.

 


Similar Articles