Date post: | 24-May-2015 |
Category: |
Documents |
Upload: | anwar-yahyawi |
View: | 238 times |
Download: | 1 times |
Microsoft Leader clubSession One – Dev Windows Phone 8
08/03/2013
APP CAMPUS
Get €50,000 for your Windows Phone app idea! The winner will also get a free trip to Finland to participate in a 4-week developer camp. Compete for the Worldwide Imagine Cup AppCampus Award! Top finalists incorporating a Windows Phone app into their project are eligible to win. Through this mobile application accelerator program, Microsoft and Nokia provide grants to fund innovative, first-to-market ideas with a fresh approach on design elegance, superior quality and performance
WINDOWS PHONE DEV CENTER
The Windows Phone Emulator
•The Windows Phone emulator runs as a Hyper-V virtual machine on your Windows PC • •It contains the same
software as a “real” phone, but built for the Windows PC platform
Page Navigation
Frame and Page •Frame •Top-level container control •PhoneApplicationFrame class •Contains the page control and system elements such as system tray and application bar •Page •Fills entire content region of the frame •PhoneApplicationPage-derived class •Contains a title •Optionally surfaces its own application bar
Using a Grid to Aid Landscape Layout
• <phone:PivotItem Header="recipe"> • <Grid> • <Grid.ColumnDefinitions> • <ColumnDefinition Width="*"/> • <ColumnDefinition Width="Auto"/> • </Grid.ColumnDefinitions> • <Grid.RowDefinitions> • <RowDefinition Height="Auto"/> • <RowDefinition Height="240"/> • <RowDefinition Height="*"/> • <RowDefinition Height="Auto"/> • </Grid.RowDefinitions> • ... • </Grid>
Handling Screen Orientation Changes Selecting Orientations
SupportedOrientations="Portrait«
SupportedOrientations="PortraitOrLandscape«
• •A XAML property for the phone application page lets you select the orientation options available
• •Your application can bind to an event which is fired when the orientation changes
Moving Elements
• private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) { if (this.Orientation == PageOrientation.LandscapeLeft || this.Orientation == PageOrientation.LandscapeRight) { DirectionsScrollViewer.SetValue(Grid.RowProperty, 1); DirectionsScrollViewer.SetValue(Grid.ColumnProperty, 1); } else { DirectionsScrollViewer.SetValue(Grid.RowProperty, 2); DirectionsScrollViewer.SetValue(Grid.ColumnProperty, 0); } }
Page Navigation •XAML apps on Windows Phone use a page-based navigation model •Similar to web page model •Each page identified by a URI •Each page is essentially stateless
private void HyperlinkButton_Click_1( object sender, RoutedEventArgs e) { NavigationService.Navigate( new Uri("/SecondPage.xaml", UriKind.Relative)); }
Navigating Back •Application can provide controls to navigate back to preceding page
•The hardware Back key will also navigate back to preceding page •No code required – built-in behaviour
private void Button_Click_1( object sender, RoutedEventArgs e) { NavigationService.GoBack(); }
Passing Data Between Pages • •Can pass string data between pages using query
strings private void passParam_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + textBox1.Text, UriKind.Relative)); }
• •On destination page protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); string querystringvalue = ""; if (NavigationContext.QueryString.TryGetValue("msg", out querystringvalue)) textBlock1.Text = querystringvalue; }
Isolated Storage Classes
• •The IsolatedStorage classes are all in the System.IO.IsolatedStorage namespace • •IsolatedStorageFile • •Represents an isolated storage area containing files and
directories • •IsolatedFileStream • •Exposes a file stream access to a file stored within isolated
storage • •IsolatedStorageSettings • •Dictionary<(Of <(TKey, TValue>)>) that stores key-value pairs
in isolated storage
Local Folder • •All read-write I/O operations restricted to local folder • •Create a files and folder structure hierarchy • •Use Isolated Settings storage to store application settings
Saving Data
private void saveGameToIsolatedStorage(string message) { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream rawStream = isf.CreateFile("MyFile.store")) { StreamWriter writer = new StreamWriter(rawStream); writer.WriteLine(message); // save the message writer.Close(); } } }
Loading Data
private string loadString() { string result = null; using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (isf.FileExists("Myfile.store") { using (IsolatedStorageFileStream rawStream = isf.OpenFile(filename, System.IO.FileMode.Open)) { StreamReader reader = new StreamReader(rawStream); result = reader.ReadLine(); reader.Close(); } } } return result; }
Capture CameraCode XAML<Button x:Name="CaptureCameraButton" Content="Capture Camera" Width="300" Height="100" Margin="0,81,156,426" Click="CaptureCameraButton_Click" /><Image Height="150" HorizontalAlignment="Left" Margin="12,348,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />Code c#private void CaptureCameraButton_Click(object sender, RoutedEventArgs e){CameraCaptureTask cct = new CameraCaptureTask();cct.Completed += new EventHandler<PhotoResult>(cct_Completed);cct.Show();}
void cct_Completed(object sender, PhotoResult e){BitmapImage bmp = new BitmapImage();bmp.SetSource(e.ChosenPhoto);image1.Source = bmp;}
Get PHOTOCode XAML• <Button x:Name="GetPhotoButton" Content="Get Photo" Width="300" Height="100" Margin="0,242,156,265"
Click="GetPhotoButton_Click" />• <Image Height="150" HorizontalAlignment="Left" Margin="12,348,0,0" Name="image2" Stretch="Fill"
VerticalAlignment="Top" Width="200" />
Code c#private void GetPhotoButton_Click(object sender, RoutedEventArgs e){PhotoChooserTask pct = new PhotoChooserTask();pct.Completed += new EventHandler<PhotoResult>(pct_Completed);pct.Show();}
void pct_Completed(object sender, PhotoResult e){BitmapImage bmp = new BitmapImage();bmp.SetSource(e.ChosenPhoto);image2.Source = bmp;}
Anwar YAHYAOUI•President du club Microsoft Leader•Email: [email protected]•Mobile: (+216) 24 23 41 73