silverlight for windows phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•a silverlight windows...

24

Upload: others

Post on 23-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used
Page 2: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Silverlight for Windows Phone 7

Erick Kurniawan, M.Kom, MCTS, MCPD, MCT [email protected] http://actual-trraining.com

Page 3: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Agenda

• Project and Solution

• Debugging Program

• Orientation Page

• Pages and Navigation

• Displaying List Of Data & Data Binding

Page 4: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Windows Phone App Frameworks

Page 5: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Silverlight for Windows Phone

• Silverlight

– Same base class libraries

– Modification for performance

– Hardware Integration

– Operating System Integration

– Phone-specific APIs

– Out of browser model

• In browser Silverlight is not supported

Page 6: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

XAML and Silverlight

• A Silverlight application is made up of pages that contain elements

• These have properties that determine where they are, how they appear and what they can do in an application

• The Visual Studio tool allows us to manipulate the page content by using the design surface and the element properties pane

Page 7: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Why do we need XAML?

• XAML allows us to separate the role of

graphic designer and programmer

– The designer should not have to see code

objects to work

– The programmer should not be held back while

the design is produced

• The XMAL file provides a separation between

the code that drives the application and the

way the application looks

Page 8: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

XAML file content

• This snippet of XAML is the description of the

firstNumberTextBox

• It contains fields that describe the position

and size of the textbox

<TextBox Height="72" HorizontalAlignment="Left" Margin="8,19,0,0" Name="firstNumberTextBox" Text="0" VerticalAlignment="Top" Width="460" TextAlignment="Center" />

Page 9: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Windows Phone Solutions

• A Silverlight Windows

Phone solution only

contains a single project

• This contains all the images

used for the icons on the

phone

• It also uses all the Windows

Phone references

Page 10: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Windows Phone Versions

• The new version of Windows Phone 7.5

– The previous (original) version was 7

• The operating system and SDK that Windows

Phone 7.5 is based on is numbered 7.1

Page 11: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

The XAP File

• The XAP file is a container that holds everything needed to run the application

• It is a Zip archive with a manifest that describes its contents

Page 12: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Running the XAP file

• When you press the “run” button in Visual Studio

the XAP file is copied to the target device

• The device opens the archive, reads the manifest

file and starts the application running

• The XAP file is also the file that is sent to a

customer who buys the program in Windows

Marketplace

Page 13: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

HOL Create Silverlight Project

Page 14: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Windows Phone Orientation

• Unlike a desktop device, users will can use a

Windows Phone in either orientation

– Portrait orientation – stood up

– Landscape orientation – laid on side

• Some applications work best in particular

orientations

• We might want to show off, and make an

application that works in either

Page 15: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Orientation Warning

• Handling multiple orientations is hard work

• It is at least twice as difficult as one orientation

– You need to design the screen twice

– You then have to add the orientation change management

• Many applications only work in one orientation

– Including the Windows Phone Start Screen

• So consider this issue carefully

Page 16: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Allowing multiple orientations private void PhoneApplicationPage_OrientationChanged( object sender, OrientationChangedEventArgs e) { if (e.Orientation == PageOrientation.PortraitUp) { setPortrait(); } else { setLandscape(); } }

• This method runs when the orientation changes and calls the appropriate setting method

Page 17: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Setting Landscape Mode private void setLandscape() { firstNumberTextBox.Margin = new Thickness(8,19,0,0); firstNumberTextBox.Width = 207; secondNumberTextBox.Margin = new Thickness(252,19,0,0); secondNumberTextBox.Width = 207; plusTextBlock.Margin = new Thickness(221,35,0,0); resultTextBlock.Margin = new Thickness(538,35,0,0); }

• This method configures the display for

landscape mode

• The Thickness value contains four elements

Page 18: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

The StackPanel container

• A StackPanel contains a number of other text

elements and stacks them up on the screen

• We don‟t have to explicitly position them, the

StackPanel does this for us

• A StackPanel can arrange things across or

down the screen

• We can nest StackPanel elements inside other

StackPanels to create complex layouts

Page 19: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Changing Orientation

HOL

19

Page 20: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Page Navigation

• The NavigationService object performs

navigation for an application

• Each Silverlight page has a Uri

• The Navigate method takes the user to the

specified page

private void page2Button_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate( new Uri("/CustomerDetailPage.xaml", UriKind.RelativeOrAbsolute)); }

Page 21: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Pages and Navigation

HOL

21

Page 22: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Data Binding

• This is a very important subject

• It provides a coupling between the data in a

program and the user interface

• It removes the need to write “glue” logic to

link program data to display elements

• It can work in two ways

– „One-way‟

– „Two-way‟

Page 23: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

List and Data Binding

HOL

23

Page 24: Silverlight for Windows Phone 7lecturer.ukdw.ac.id/anton/download/pbk10.pdf•A Silverlight Windows Phone solution only contains a single project •This contains all the images used

Reference

• http://www.microsoft.com/download/en/detai

ls.aspx?id=1678

• http://nice.or.id/curriculums/