Professional Documents
Culture Documents
Windows Store Apps Essentials
Windows Store Apps Essentials
Windows Store Apps Essentials
Session - 1
Windows Store is an Application Store, which was established under Windows 8. It provides
various apps, similar to Google, Apple, or BlackBerry apps and allows the distribution and
purchase of apps designed for Windows 8. These apps can be developed for Windows 8 PCs and
Tablets.
Windows 8 or higher
Live Tiles
Live tiles are used to show the live updates from the Internet. These are a key part
of Start screen. This tile dynamically synchronizes stock updates, live news, and
calendar from Hotmail accounts and displays the status on the home screen. They
are used for making the design fast and fluid. A Live tile can either be static or live.
Splash Screen
Whenever any app is started, a splash screen is displayed. This can also be
configured to show when a dynamic update of any app is going on. It normally
consists of screen image and background color. A well-designed splash screen will
make application more lively, attractive, and inviting.
Hub Control
A hub control helps you to create multiple sections. It is displayed in the app’s main
content. It is also called ‘Hub View’ or ‘Hub Page’. It gives flexibility to design and
customize the app to suit our brand needs. It uses a hierarchical navigation pattern.
App Bar
App bars are applied to perform actions on UI elements, such as filtering results or
navigating within the app, or deleting photos. They are invoked by swiping from the
top or bottom of the screen or by right-clicking the current app. They provide easy
access to various commands. They can also be hidden or made context sensitive.
Detail Page
The detail page is the content page for all the apps developed for Windows 8. It
shows the actual information related to the current app. When the user selects a
particular option or command, this screen is displayed to show the details related to
the selected option or command.
When you move the mouse on the right side of the screen, you can see the Search, Share,
Start, Device, and Settings options, these are called charms. These charms can also be
displayed by tapping Win+C keys. It is a universal toolbar for Windows 8. It can be used to work
productively and add beauty to Windows Store apps. Following figure shows the charms used
in Windows 8:
Search
Search command is used to search any files from Windows Explorer, SkyDrive, or from the Bing Search
Engine. Press the Win+S keys and enter the file name or text to be searched. This search charm will
show the matching result with links. You can open the file just by clicking the given links.
By default, it shows the contents from the PC and SkyDrive at the beginning and then, it lists the
contents from the Web. If you wish to go back to the Search charm again, you can point the mouse
cursor to the upper-left corner and click the given thumbnail. An example of using Search charm to
search for Lock Screen as shown in the following figure:
you can share files, photos, or thoughts with known people, any social media network, and
share the SkyDrive files with any contact, link by selecting Share button on the charm and
then, selecting the person with whom you wish to share the app or link, as shown in the
following figure:
We can modify the settings of the share content by choosing the Settings charm button and
navigating to Change PC Settings.
Start
Devices
Settings
Layouts are used for sizing and positioning objects in the current UI. If you wish to position your
objects properly, you must put them in containers such as Panel, Canvas, Stack Panel, and Grid
controls provided by XAML for this purpose. These containers allow us to position and arrange
our objects inside the UI.
In Dynamic layout, the user can fix their own size in the user
interface based on the screen resolution. It does not specify the
Dynamic layout exact positioning of the child elements. The location of the
child elements is automatically adjusted as per the changes in
the resolution of the screen. Controls such as Grid,
StackPanel, and VariableSizedWrapGrid are used to
define and create Dynamic layout.
Canvas
In XAML, the default container is Canvas. It is a type of absolute layout. We can set its
Canvas.Left and Canvas.Top properties to its exact position in the parent container.
Note - Canvas has a property called Canvas.Index, which can be set on each of
the child elements.
Following example shows how to design a layout in the Canvas using a step-by-step
procedure:
Launch Visual Studio 2013.
Create a new project using File New Project Blank App (XAML).
Enter the Project name as CanvasDemo and click OK.
Add the code as shown in Code Snippet to MainPage.xaml.
Following Code Snippet explains how to create a Canvas which has a Rectangle UI element defined
inside it:
Code
Snippet:
<Page
x:Class=”CanvasDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using: CanvasDemo”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/ markup-compatibility/2006”
mc:Ignorable=”d”>
<Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<Canvas Background=”Black”>
<Rectangle Canvas.Left=”100” Canvas.Top=”50” Fill=”Red” Width=”50”
Height=”150” />
</Canvas>
</Grid>
</Page
StackPanel
The StackPanel container is applied to align the child elements either horizontally or vertically.
The user can specify the Orientation property of the child element in the StackPanel. You
can specify the Height and Width properties of the control. If you specify orientation as
Horizontal, then all the elements will be arranged in horizontal order. There are two options –
Horizontal or Vertical.
Create a blank application by selecting File New Project Blank App (XAML).
Code
Snippet:
<Page
x:Class=”StackPanelDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:StackPanelDemo”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/markup-ompatibility/2006”
mc:Ignorable=”d”>
<StackPanel Margin=”20”>
<Rectangle Fill=”Blue” Width=”25” Height=”25” Margin=”10” />
<Rectangle Fill=”Green” Width=”25” Height=”25” Margin=”10” />
<Rectangle Fill=”Red” Width=”25” Height=”25” Margin=”10” />
<Rectangle Fill=”Yellow” Width=”25” Height=”25” Margin=”10” />
</StackPanel>
</Page>
Grid
The Grid panel is utilized to set the controls in array dimensions similar to multi-row and
multi-column layouts. The user can specify a Grid’s row and column definitions by using the
RowDefinitions and ColumnDefinitions properties within the Grid element. The
user can specify the Grid.Column and Grid.Row properties, and set the number of rows
and columns that should be there in the current Grid.
Following Code Snippet explains how to create Grid with columns and rows:
Code
Snippet:
<Page
x:Class=” GridDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:App25”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006”
mc:Ignorable=”d”>
<Grid Grid.Column=”4” Grid.Row=”2” Background=”Beige” Opacity=”10”
Visibility=”Visible”>
<Button Content=”Click Me 1” HorizontalAlignment=”Left” Margin=”59,27,0,0”
VerticalAlignment=”Top” Height=”126” Width=”256” Background=”Blue”
Foreground=”White”/>
<Button Content=”Click Me 2” HorizontalAlignment=”Left” Margin=”331,189,0,0”
VerticalAlignment=”Top” Height=”126” Width=”256” Background=”Blue”
Foreground=”White”/>
<Button Content=”Click Me 3” HorizontalAlignment=”Left” Margin=”916,27,0,0”
VerticalAlignment=”Top” Height=”126” Width=”256” Background=”Blue”
Foreground=”White”/>
Code Snippet
(Cont):
VariableSizedWrapGrid
VariableSizedWrapGrid is used to style the grid layout panel for each tile or cell, which
change their sizes based on contents in it. The elements are arranged in rows or columns and
are automatically wrapped until the MaximumRowsOrColumns value is reached.
Each cells size is specified using ItemHeight and ItemWidth (in pixels). Child elements can
use VariableSizedWrapGrid.ColumnSpan and
VariableSizedWrapGrid.RowSpan (values as cell counts) to adjust inside the screen.
WrapGrid and VirtualizingStackPanel are panels that can only be used to display
items in an ItemsControl.
Code
Snippet:
<Page
x:Class=” VariableSizedWrapGridDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:App26”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/ markup- compatibility/2006”
mc:Ignorable=”d”>
<Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<VariableSizedWrapGrid Orientation=”Horizontal”>
<Rectangle Width=”150” Height=”400” Margin=”50” Fill=”Blue” />
<Rectangle Width=”150” Height=”50” Margin=”5” Fill=”Red” />
<Rectangle Width=”150” Height=”150” Margin=”15” Fill=”Green” />
<Rectangle Width=”150” Height=”300” Margin=”5” Fill=”Red” />
<Rectangle Width=”150” Height=”180” Margin=”5” Fill=”Yellow” />
</VariableSizedWrapGrid>
</Grid>
</Page>
When the user needs to access more than one task at a time, he/she can snap the screen.
The default width of a snap screen is 320px wide. To create a snap screen, the user has to
navigate the mouse pointer to the upper-left part of the screen and drag the thumbnail to
the right. The user must design the apps, which look good when viewed in any size, so that
the app can support different resolutions and orientations.
Note - Windows 8 allows snapping feature when the screen resolution is more than 1366 x 768. In
Windows 8.1, the minimum resolution is not required. It works with all resolution types.
The user either can change the size of some apps or can display many apps on single screen. The
minimum height of an app always fits the height of the screen.
The main problems within the presentation layer of the application lies under
business logic, business services, and data.
To create and use these components, the user must understand fundamental UI
concepts.
The UI also provides tools for designing user interfaces in app. UIs can make use of
resources defined in XAML.
A resource can be accessed and used anywhere in the application. Brushes and styles are the
best instances of resources. Virtually, anything can be changed to a resource.
Solid, Gradient, or Tile brush can be created as a resource and used in the application. The
user can assign resources at object-level, document-level, dictionary-level, and application-
level. The resource editors help the user to produce a resource file with .resw extension.
Following steps show how to use the TextBlock, TextBox, and Button controls and
how to write the code to handle the Button_Click event:
Create a blank application by selecting File New Project Blank App (XAML).
Code
Snippet:
<Page
x:Class=”EventHAndlingDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using: EventHAndlingDemo “
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/ markup-compatibility/2006”
mc:Ignorable=”d”>
<Grid Background=”Beige”>
<TextBlock Text=”Message” Height=”40” Width=”200” Margin=”20”
VerticalAlignment=”Top” HorizontalAlignment=”Left” Foreground=”Blue”
FontSize=”30”/>
<TextBox Name=”MyName” Height=”40” Width=”300” VerticalAlignment=”Top”
HorizontalAlignment=”Left” Margin=”160,20”/>
Double-click the button control or open MainPage.xaml.cs file and add the code as
shown in the following Code Snippet:
Code
Snippet:
Resource dictionary has a collection of objects (resources) inside the dictionary, which can be
developed by the user using the programming code in C#. The ResourceDictionary has
two properties, namely, FrameworkElement.Resources and
Application.Resources. Generally, the user prescribes
FrameworkElement.Resources value inside the root element of the app page.
Resource dictionary can be divided into Styles, Templates, Colors, Brushes, and Transmutes. The
MergedDictionary can be used to merge many dictionaries and refers to the external file
as shown in the following figure:
Following example shows how to create a resource dictionary. The resource files can be
accessed through the Windows.ApplicationModel.Resources.ResourceLoader
namespace.
Create a new project named DictionaryDemo.
Right-click Project Add New Item as shown in the following figure.
Enter the code as shown in Code Snippet into the dictionary file,
MyDictionary.xaml.
Code
Snippet:
<ResourceDictionary
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”>
<SolidColorBrush x:Key=”scbColor” Color=”#800800”/>
</ResourceDictionary>
Add the code as shown in Code Snippet to MainPage.xaml file. This is where
the Resource Dictionary will be applied.
Code
Snippet:
<Page
x:Class=”DictionaryDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:DictionaryDemo”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006”
xmlns:local=”using:DictionaryDemo.DictionaryDemo_XamlTypeInfo”
mc:Ignorable=”d”>
<Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<TextBlock Text=”Hello World” Foreground=”{StaticResource scbColor}”
FontSize=”30” Margin=”573,78,593,0” Height=”50” Width=”200”
VerticalAlignment=”Top”/>
</Grid>
</Page>
Using the visual properties from the resource dictionary, the user can
define styles for any controls.
First, create a page CheckBoxDemo.xaml and add the code as shown in Code Snippet.
Code
Snippet:
<Page
x:Class=”CheckBoxDemo.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:App3”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006”
mc:Ignorable=”d”>
<Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<CheckBox Content=”CheckBox” IsThreeState=”True” Margin=”100”/>
<CheckBox Content=”CheckBox” IsThreeState=”True” Margin=”200”/>
<CheckBox Content=”CheckBox” IsThreeState=”True” Margin=”300”/>
</Grid>
</Page>
The user can bind the data using simple methods in C# to interact with the controls. For example,
the ForeColor of a TextBox can be called through SolidColorBrush to change the style of
the value, which can be change of its data. Code Snippet shows how to assign the color for
TextBox. The binding source is a property of the Style class.
Code
Snippet:
When an app is created, the user must ensure that there is support for page navigation
between pages. There are some predefined templates, which are preinstalled in Visual Studio
2013 for navigation. Following steps show how to navigate within the pages in the
application:
Create a blank application named PageNavigation.
Add two pages named Navigate1.xaml and Navigate2.xaml, using the option
as shown in the following figure:
Design the page by creating two buttons inside MainPage.xaml as shown in the following
figure:
Code
Snippet:
Code
Snippet:
Code
Snippet:
Code
Snippet:
Code
Snippet:
Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>
<Button Content=”Go Back to Home” HorizontalAlignment=”Left”
VerticalAlignment=”Top” Margin=”644,394,0,0” Height=”95” Width=”190”
Click=”Button_Click”/>
<TextBlock HorizontalAlignment=”Left” Margin=”540,201,0,0”
TextWrapping=”Wrap” Text=”Welcome to Page 2” VerticalAlignment=”Top”
Height=”89” Width=”526” FontSize=”48”/>
</Grid>
Code
Snippet:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(MainPage), null);
}
Code
Snippet:
<StackPanel>
<StackPanel.Resources>
Storyboard x:Name=”EnterStoryboard”>
<FadeOutThemeAnimation Storyboard.TargetName=”ftaRect” />
</Storyboard>
<Storyboard x:Name=”ExitStoryboard”>
<FadeInThemeAnimation Storyboard.TargetName=” ftaRect” />
</Storyboard>
</StackPanel.Resources>
<Rectangle x:Name=”ftaRect” PointerEntered=”Rectangle_Click”
PointerExited=”Rectangle_Click2”
Fill=”Gray” Width=”100” Height=”300” />
</StackPanel>
While creating empty container, the user can use content transitions
to create new items.
The user can move the content from one part of the container to
another part using content transitions.
This transition is already in-built in the container. When an animation
is displaying the content from the left side, then the new content
must come from the right.
Arrange each content logically. When there is more than one
container, then update them by triggering all together with transition
animation.
Whenever the whole page changes, the user must not use content
transition animations, instead the user can call the Page transition
animations.
Use Fade animations to refresh the content instead of refreshing the
container.
Key frame animations are specified with the animation timeline and it is declared by using
different sub classes for each animation. If the user targets Double data type values for
animation, then he/she must have animation types such as Linear, Easing, Discrete, or
Spline.
FillBehavior
This does not have any effect. It controls what should be done
when it reaches the last key frame.
RepeatBehavior:
If the user sets the Duration, inside the timeline, then it will
repeat up to the duration specified.
SpeedRatio:
It is a property, which is not used in most often. It
sets the speed ratio of the animation.
Code
Snippet:
<StackPanel>
<StackPanel.Resources>
<Storyboard x:Name=”SampleBoard”>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName=”myRect”
Storyboard.TargetProperty=”(UIElement.RenderTransform).
(ScaleTransform.ScaleY)”>
<LinearDoubleKeyFrame Value=”1” KeyTime=”0:0:0” />
<LinearDoubleKeyFrame Value=”1.2” KeyTime=”0:0:4” />
<LinearDoubleKeyFrame Value=”2” KeyTime=”0:0:5” />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</StackPanel.Resources>
</StackPanel>
Code
Snippet:
Page Transitions
The page will be animated within the view, which means it
will be shown at the time of each transition. Page Transitions
have their own Application Programming Interfaces (APIs)
namely, enterPage and exitPage.
Fade In/Out
The controls or UI will be animated
using Fade In/Out. The Fade In/Out
Content Transitions have their own APIs namely, fadeIn
and fadeOut.
The contents in the page will be
animated independently. Content
Transitions have their own APIs
namely, enterContent and
exitContent.
Crossfade
When there is a change inside content, Expand/Collapse
this crossfade functionality will be
called smoothly. It uses crossfade When the user hovers over the content,
API. it will expand the sub content. Collapse
animation is called when the mouse is
hovering out the content. This
Expand/Collapse uses
createExpandAnimation and
createCollapseAnimation API.
Reposition
To show the content to a new position, the Pointer Up/Down
Reposition animation function is used. The When the mouse is hovered over a tile,
Reposition function uses the the animation is invoked. This Pointer
createRepositionAnimation API. Up/Down uses pointerUp and
pointerDown API.
Show/Hide Popup
To show or hide the contextual UI, the Show/Hide Popup
animation is called. This uses showPopup and hidePopup API.
This is shown when the mouse is moved to the bottom of the page,
inside any app.
Show/Hide Panel
AddDeleteThemeTransition
ContentThemeTransition
TransitionCollection Class
This class is called when there is more than one object.
EdgeUIThemeTransition
The code shows how to call the
TransitionCollection class and get the
EntranceThemeTransition objects in a list.
public sealed class trsnCol:
PopupThemeTransition
IList<Transition>,
IEnumerable<Transition>
ReorderThemeTransition
RepositionThemeTransition
Border.ChildTransitions
ContentControl.ContentTransitions
ContentPresenter.ContentTransitions
ItemsControl.ItemContainerTransitions
ItemsPresenter.FooterTransitions
ItemsPresenter.HeaderTransitions
ListViewBase.FooterTransitions
ListViewBase.HeaderTransitions
Panel.ChildrenTransitions
Popup.ChildTransitions
SettingsFlyoutTemplateSettings.ContentTransitions
UIElement.Transitions
Transformation
Consider an example that shows how to transfer data from one page to another.
Create a blank application.
Create two pages named First.xaml and Second.xaml.
Code
Snippet:
<Page
x:Class=”navigation.page1”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:navigation”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006”
mc:Ignorable=”d”>
<Grid Background=”{StaticResource ApplicationPageBackgroundThemeBrush}”>
Code Snippet
(Cont):
<StackPanel>
<TextBlock Name=”txtSample” Text=”User Name” FontSize=”22” Margin=”50”
Height=”50”Width=”150”/>
</StackPanel>
<StackPanel Orientation=”Vertical” Margin=”100”>
<StackPanel Orientation=”Horizontal” >
<TextBlock Name=”txtb_f_name” Text=”Please enter your Name” FontSize=”22”/>
<TextBox Name=”txtF_name” Height=”50” Width=”150”></TextBox>
</StackPanel>
</StackPanel>
<StackPanel Grid.Row=”1” Margin=”550”>
<HyperlinkButton x:Name=” btnProceed” Content=”Next Page”
FontSize=”22”Margin=”110” Width=”500” Click=”btnProceed_Click”/>
</StackPanel>
</Grid>
</Page>
Code
Snippet:
Code
Snippet:
<Page x:Class=”navigation.page2”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local=”using:navigation”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006”
mc:Ignorable=”d”>
<Grid Background=”{StaticResource
ApplicationPageBackgroundThemeBrush}”>
<StackPanel Margin=”463,20,-463,-20”>
<TextBlock Name=”lbl” Text=”Secondpage” FontSize=”22”/>
</StackPanel>
Code Snippet
(Cont):
Code
Snippet:
{ this.Frame.Navigate(typeof(First));
Windows Store is a Windows 8 based platform that allows for the distribution and
purchase of apps designed for Windows 8.
App bars are applied to perform actions on substances, such as filtering results or
navigating within the app or deleting photos.
In Windows Store apps, you can use XAML to create various types of containers and
controls.
User can create a snap screen by navigating the mouse pointer to the top left of the
screen and dragging the thumbnail to the right.
Windows apps can run on different resolutions from a small tablet to a laptop or
desktop.
By using resource dictionaries, the code in Windows Store apps can be made reusable.
A ResourceDictionary has two properties, namely, FrameworkElement.Resources and
Application.Resources to take the values.