Windows 10 – Universal Windows Platform – Adaptive App

Step 1

Download Visual Studio Community 2015 and install it onto your computer, if it’s already downloaded and installed select Launch to start Visual Studio Community 2015 or if it has already been downloaded and installed then start the application you may also need to Enable your device for development.

2015-visual-studio

Step 2

Once Visual Studio Community 2015 has started select File, then New, then Project… from the Menu.

2015-file-new-project

Step 3

From the New Project window select Visual C# from Installed, Templates then select Blank App (Windows Universal) from the list, then type in a Name and select a Location to save to before selecting Ok to create the Project.

2015-new-project

Step 4

Once done select from the Menu, Project, then Add New Item…

2015-project-add-new-item

Step 5

From the Add New Item window select Visual C# from Installed and select Code then select Code File from the list, then type in the Name as Library.cs before selecting Add to add the file to the Project

2015-add-new-item-library

Step 6

Once in the Code View for Library.cs the following should be entered:

using System;
using System.Collections.Generic;
using Windows.System;
using Windows.UI.Xaml.Controls;

public class Setting
{
    public string Name { get; set; }
    public string Icon { get; set; }
    public string Value { get; set; }
}

public class Library
{
    public List<Setting> Settings
    {
        get
        {
            return new List<Setting>() {
            new Setting() { Name = "Display", Icon = "\uE7F8", Value = "display" },
            new Setting() { Name = "Notifications", Icon = "\uE91C", Value = "notifications" },
            new Setting() { Name = "Battery", Icon = "\uE8BE", Value = "batterysaver" },
            new Setting() { Name = "Storage", Icon = "\uE8B7", Value = "storagesense" },
            new Setting() { Name = "Data", Icon = "\uE774", Value = "datausage" },
            new Setting() { Name = "Personalisation", Icon = "\uE771", Value = "personalization" },
            new Setting() { Name = "Privacy", Icon = "\uE1F6", Value = "privacy" },
            new Setting() { Name = "Developers", Icon = "\uEC7A", Value = "developers" }
            };
        }
    }

    public static async void Launch(GridView grid)
    {
        string value = ((Setting)(grid.SelectedItem)).Value;
        await Launcher.LaunchUriAsync(new Uri("ms-settings:" + value));
    }
}

It should then appear as such:

2015-adaptive-app-library

Step 7

From the Solution Explorer select App.xaml

2015-app-library

Step 8

Select from the Menu, View then Designer

2015-view-designer

Step 9

The XAML View will be displayed and in this above </Application> enter the following XAML:

<Application.Resources>
	<DataTemplate x:Key="Desktop">
		<Grid Width="200" Height="200">
			<StackPanel VerticalAlignment="Center">
				<Viewbox Height="50" Width="50" HorizontalAlignment="Center">
					<TextBlock Text="{Binding Icon}" FontFamily="Segoe MDL2 Assets" 
						Foreground="{ThemeResource SystemControlHighlightAccentBrush}"/>
				</Viewbox>
				<TextBlock Text="{Binding Name}" Margin="10" HorizontalAlignment="Center" 
					Style="{StaticResource FlyoutPickerTitleTextBlockStyle}"/>
			</StackPanel>
		</Grid>
	</DataTemplate>
	<ItemsPanelTemplate x:Key="DesktopItems">
		<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="4"/>
	</ItemsPanelTemplate>
	<DataTemplate x:Key="Mobile">
		<Grid Width="200">
			<StackPanel Orientation="Horizontal">
				<Viewbox Height="25" Width="25" HorizontalAlignment="Left">
					<TextBlock Text="{Binding Icon}" FontFamily="Segoe MDL2 Assets" 
						Foreground="{ThemeResource SystemControlHighlightAccentBrush}"/>
				</Viewbox>
				<TextBlock Text="{Binding Name}" Margin="10" HorizontalAlignment="Left" 
					Style="{StaticResource BodyTextBlockStyle}"/>
			</StackPanel>
		</Grid>
	</DataTemplate>
	<ItemsPanelTemplate x:Key="MobileItems">
		<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="1"/>
	</ItemsPanelTemplate>
</Application.Resources>

It should appear as such:

2015-adaptive-app-app-xaml

Step 10

From the Solution Explorer select MainPage.xaml

2015-mainpage-library

Step 11

Select from the Menu, View then Designer

2015-view-designer

Step 12

The Design View will be displayed along with the XAML View and in this below <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”> enter the following XAML:

<GridView Name="Display" HorizontalAlignment="Center" VerticalAlignment="Center"  
		SelectionChanged="Display_SelectionChanged" 
		ItemsSource="{x:Bind Path=Library.Settings}"/>
<VisualStateManager.VisualStateGroups>
	<VisualStateGroup>
		<VisualState>
			<VisualState.StateTriggers>
				<AdaptiveTrigger MinWindowWidth="720"/>
			</VisualState.StateTriggers>
			<VisualState.Setters>
				<Setter Target="Display.ItemTemplate" Value="{StaticResource Desktop}"/>
				<Setter Target="Display.ItemsPanel" Value="{StaticResource DesktopItems}"/>
			</VisualState.Setters>
		</VisualState>
		<VisualState>
			<VisualState.StateTriggers>
				<AdaptiveTrigger MinWindowWidth="0"/>
			</VisualState.StateTriggers>
			<VisualState.Setters>
				<Setter Target="Display.ItemTemplate" Value="{StaticResource Mobile}"/>
				<Setter Target="Display.ItemsPanel" Value="{StaticResource MobileItems}"/>
			</VisualState.Setters>
		</VisualState>
	</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

It should appear as such:

2015-adaptive-app-mainpage-xaml

Step 13

Select from the Menu, View then Code

2015-view-code

Step 14

Once in the Code View below the public MainPage() { … } the following should be entered:

public Library Library = new Library();

private void Display_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
	Library.Launch(Display);
}

It should then appear as such:

2015-adaptive-app-mainpage-code

Step 15

That completes the Universal Windows Application so Save the Project then select the Debug and Simulator option to run the Application

2015-simulator

Step 16

Once the Simulator has started the Application should then appear displaying the Large view of the Application

2015-adaptive-app-simulator-run

Step 17

To Exit the application select Stop Debugging in Visual Studio Community 2015

2015-stop

Step 18

Another option is to run as a Windows 10 Mobile application, select Debug and select Emulator 10.0.10586.0 WVGA 4 inch 512MB option to run the Application

2015-emulator

Step 19

Once the Emulator has started the Application should then appear displaying the Small view of the Application

2015-adaptive-app-emulator-run

Step 20

To Exit the application select Stop Debugging in Visual Studio Community 2015

2015-stop

Creative Commons License

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s