Thursday, November 15, 2012

What's new in Windows Phone 8

?

Line 125: Line 125:
?

|} </li>

?

|} </li>

?

<li>'''C++ cannot access managed Mango APIs: '''C++ code can only use new WP8 APIs from WinPRT. As a result C++ code cannot access any of the existing Mango APIs. That means C++ apps are limited to the following new windows phone namespaces:

?

<li>'''C++ cannot access managed Mango APIs: '''C++ code can only use new WP8 APIs from WinPRT. As a result C++ code cannot access any of the existing Mango APIs. That means C++ apps are limited to the following new windows phone namespaces:

?

: <code text>

+

</li>

?+

</ol>

?+

<code text>

?

Windows.ApplicationModel

?

Windows.ApplicationModel

?

Windows.ApplicationModel.Activation

?

Windows.ApplicationModel.Activation

Line 184: Line 186:
?

Windows.UI.Popups

?

Windows.UI.Popups

?

Windows.UI.ViewManagement

?

Windows.UI.ViewManagement

?

</code></li>

+

</code>

?

</ol>

+
??
?

<div style="text-align:right;">[[#top|Go back to top]]</div>

?

<div style="text-align:right;">[[#top|Go back to top]]</div>


Latest revision as of 23:05, 14 November 2012

Article Metadata

Code Example
Compatibility

Platform(s): Windows Phone 8 and later


Article

Introduction

The release of Windows Phone 8 marks a significant milestone in the evolution of Microsoft's operating system for mobile phones. For users this new release means expanded hardware access, support for high-end gaming, and better OS integration - all of which will soon be seen on the Nokia Lumia 920 and Nokia Lumia 820 phones.

For developers the changes are no less significant, bringing many new APIs. These APIs simplify the coding of features you may already be adding to your Windows Phone apps, but also offers many new ones too. This article will introduce you to the most significant API additions and changes.

Through the article an example application is used to show the practical code you need to write to make use of these new features. To create your own version of this application you will need the Windows Phone 8 SDK, which can be downloaded from http://go.microsoft.com/fwlink/?LinkID=261873. You can get a complete version of the example app here: Media:WhatsNewInWP8 FullExample.zip.

Native: DirectX, C++, and Direct3D graphics

A subset of DirectX has been introduced into Windows Phone 8 to allow for native high-end high-performance games. C++ has also been introduced, primarily for use in those high-end games.

In Visual Studio 2012 you can create a ?Windows Phone Direct3D Application? which uses these new features.

Run the default new project and you will see a spinning 3D cube.

3D spinning cube in Direct3D

Direct3D isn't magic. It's pretty easy to go into CubeRenderer.cpp, find the place where 8 points are used to define the cube

VertexPositionColor cubeVertices[] = {     {XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f)},     {XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f)},     {XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f)},     {XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f)},     {XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f)},     {XMFLOAT3( 0.5f, -0.5f,  0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f)},     {XMFLOAT3( 0.5f,  0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f)},     {XMFLOAT3( 0.5f,  0.5f,  0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f)}, };


It's also quite simple to reduce the definition t 4 points and get a tetrahedron, as follows:

VertexPositionColor cubeVertices[] = {     {XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f)},     {XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f)},     {XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f)},     {XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f)},     //{XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f)},     //{XMFLOAT3( 0.5f, -0.5f,  0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f)},     //{XMFLOAT3( 0.5f,  0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f)},     //{XMFLOAT3( 0.5f,  0.5f,  0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f)}, };


Now, running the app, displays a flat tetrahedron spinning in 3D.

3D spinning tetrahedron in Direct3D

There are a few important caveats with this new feature set.

  1. Programming languages: C++ is meant to be used alongside DirectX. C++ with XAML or C# with DirectX aren't supported out of the box. Even though achieving interoperability between the two platforms is possible.
  2. Direct3D feature level: The supported feature level for Direct3D is Level9_3 for all Windows Phone 8 devices. Whereas Windows 8 Store apps can support additional feature levels. That limits what we can do with Direct3D. But it also creates an easy programming model for DirectX across all Windows Phone 8 devices and potential for game code reuse between Windows Phone 8 and Windows 8. Here's a partial list of Direct3D 11.1 features supported in feature level 9_3:

    Supported Direct3D featuresets in Level9 3

  3. DirectX support: Direct3D is only one technology in the larger family of technologies known as ?DirectX?. Not all of those technologies are supported on Windows Phone 8 and even those that are supported are a subset of the desktop API. You can see a full list of those technologies here.
    Topic Supported WP8? Description
    Direct2D

    No

    Direct2D is a hardware-accelerated, immediate-mode, 2-D graphics API that provides high performance and high-quality rendering for 2-D geometry, bitmaps, and text.
    Direct3D Yes Direct3D enables you to create 3-D graphics for games and scientific apps.
    DirectWrite

    No

    DirectWrite supports high-quality text rendering, resolution-independent outline fonts, and full Unicode text and layouts.
    DirectXMath Yes DirectXMath provides an optimal and portable interface for arithmetic and linear algebra operations on single-precision floating-point vectors (2D, 3D, and 4D) or matrices (3?3 and 4?4).
    XAudio2 Yes Provides a signal processing and mixing foundation for games. XAudio2 replaces DirectSound.
    XInput

    No

    Describes how to use the XInput API to interact with the Xbox 360 Controller when it is connected to a Windows computer. XInput replaces DirectInput.
    Windows Imaging Component (WIC)

    No

    The Windows Imaging Component (WIC) is an extensible platform that provides low-level API for digital images. WIC supports the standard web image formats, high dynamic range images, and raw camera data.
  4. C++ cannot access managed Mango APIs: C++ code can only use new WP8 APIs from WinPRT. As a result C++ code cannot access any of the existing Mango APIs. That means C++ apps are limited to the following new windows phone namespaces:
Windows.ApplicationModel Windows.ApplicationModel.Activation Windows.ApplicationModel.Core Windows.ApplicationModel.DataTransfer Windows.ApplicationModel.Store Windows.Devices.Geolocation Windows.Devices.Input Windows.Devices.Sensors Windows.Foundation Windows.Foundation.Collections Windows.Foundation.Diagnostics Windows.Foundation.Metadata Windows.Graphics.Display Windows.Management.Deployment Windows.Networking Windows.Networking.Connectivity Windows.Networking.Proximity Windows.Networking.Sockets Windows.Phone.ApplicationModel Windows.Phone.Devices.Notification Windows.Phone.Devices.Power Windows.Phone.Graphics.Interop Windows.Phone.Input.Interop Windows.Phone.Management.Deployment Windows.Phone.Media.Capture Windows.Phone.Media.Devices Windows.Phone.Networking.NetworkOperators Windows.Phone.Networking.Voip Windows.Phone.PersonalInformation Windows.Phone.PersonalInformation.Provisioning Windows.Phone.Speech.Recognition Windows.Phone.Speech.Synthesis Windows.Phone.Speech.VoiceCommands Windows.Phone.Storage.SharedAccess Windows.Phone.System Windows.Phone.System.Analytics Windows.Phone.System.Memory Windows.Phone.System.Power Windows.Phone.System.Profile Windows.Phone.System.UserProfile Windows.Phone.System.UserProfile.GameServices.Core Windows.Phone.UI.Core Windows.Phone.UI.Input Windows.Security.Authentication.OnlineId Windows.Storage Windows.Storage.FileProperties Windows.Storage.Pickers Windows.Storage.Search Windows.Storage.Streams Windows.System Windows.System.Display Windows.System.Threading Windows.System.Threading.Core Windows.UI Windows.UI.Core Windows.UI.Input Windows.UI.Popups Windows.UI.ViewManagement

Native: Interoperability between DirectX and C++, and XAML and C#

One of the coolest features of the new DirectX and C++ support is its easy integration with XAML and C#.

We can interweave XAML and DirectX using the new <DrawingSurface /> and <DrawingSurfaceBackgroundGrid /> controls.

<DrawingSurface x:Name="DrawingSurface" />

Because DirectX drawing surfaces can be just another element in an XAML page, we can easily integrate it with other XAML elements. This trivial example illustrates placing a button on top of a DirectX DrawingSurface.

<Grid x:Name="LayoutRoot" Background="Transparent">     <DrawingSurface x:Name="DrawingSurface" />     <Button Margin="20" Content="Tell DirectX this button was clicked"             Height="70" VerticalAlignment="Top"/> </Grid>

The result, with the button overlaid on DirectX DrawingSurface is shown below. It even interleaves the background colour.

XAML Button overlaying DirectX

It's also possible for a C++ assembly to expose dedicated endpoints for C# code to communicate with and vice versa.

For example, in the example app you can expose the following method header in the Direct3DInterop.h header file:

public:     Direct3DInterop();     Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider(); ?     // Event Handlers     void MyButtonWasClicked();

Then implement this method in the Direct3DInterop.cpp so it prints out something to the debug console.

void Direct3DInterop::MyButtonWasClicked() {     OutputDebugString(L"Button was clicked!"); }

And from C# code you can now invoke this new method.

private Direct3DInterop m_d3dInterop = new Direct3DInterop(); private void Button_Click_1(object sender, RoutedEventArgs e) {     m_d3dInterop.MyButtonWasClicked(); }

Debugging the app shows the output string in the debug console. But first you need to start debugging the native codebase in the app. To do this open the project properties and change to the native debugger.

Changing application debugging to Native Only

Now run the app and click the button, you will see the following debug message in the output window:

Output window showing a button click passed to C++

This tells you that the XAML button click made a C# interop call successfully to the C++ codebase (that call could then affect DirectX code). The interoperability between DirectX and C++ and XAML and C# is pretty powerful.

Speech: Text-to-Speech

Text-to-speech (TTS) is now built into Windows Phone 8.

TTS was possible in previous versions of Windows Phone using an online service from Bing. If you have tried to work with this service you may have had multiple issues: Bing Translator wasn't really built for quality text-to-speech ? so the speech sounded mechanical ? it took a lot of work to setup and it required a network connection. All of those problems are solved with WP8: TTS sounds very natural, supports a range of languages, is added with only 2 lines of code, and works offline with no data connection.

The "Hello world" code sample for TTS is quite simple:

private async void TTS_HelloWorld(object sender, RoutedEventArgs e) {     var text2speech = new SpeechSynthesizer();     await text2speech.SpeakTextAsync("OMG! Hello world!"); }

When you run the app you will hear this audio: The media player is loading...

One of the cool things about TTS in WP8 is that you can change the voice used to read out text. And you've got a myriad of languages and voices to use. Voices differ from one another based on gender and which culture they're optimised for. This example uses all of the installed voices in a single sample

private async void TTS_AllVoices(object sender, RoutedEventArgs e) {     foreach (var voice in InstalledVoices.All)     {         Debug.WriteLine(voice.DisplayName + ", " +             voice.Language + ", " +             voice.Gender + ", " +             voice.Description);         using (var text2speech = new SpeechSynthesizer())         {             text2speech.SetVoice(voice);             await text2speech.SpeakTextAsync("Hello world! I'm " + voice.DisplayName + ".");         }     } }

When run, you will hear this audio: The media player is loading...

You should also see the following debug output:

Microsoft Zira Mobile, en-US, Female, Microsoft Zira Mobile - English (United States) Microsoft Stefan Mobile, de-DE, Male, Microsoft Stefan Mobile - German (Germany) Microsoft George Mobile, en-GB, Male, Microsoft George Mobile - English (United Kingdom) Microsoft Susan Mobile, en-GB, Female, Microsoft Susan Mobile - English (United Kingdom) Microsoft Heera Mobile, en-IN, Female, Microsoft Heera Mobile - English (India) Microsoft Ravi Mobile, en-IN, Male, Microsoft Ravi Mobile - English (India) Microsoft Mark Mobile, en-US, Male, Microsoft Mark Mobile - English (United States) Microsoft Katja Mobile, de-DE, Female, Microsoft Katja Mobile - German (Germany) Microsoft Laura Mobile, es-ES, Female, Microsoft Laura Mobile - Spanish (Spain) Microsoft Pablo Mobile, es-ES, Male, Microsoft Pablo Mobile - Spanish (Spain) Microsoft Raul Mobile, es-MX, Male, Microsoft Raul Mobile - Spanish (Mexico) Microsoft Sabina Mobile, es-MX, Female, Microsoft Sabina Mobile - Spanish (Mexico) Microsoft Julie Mobile, fr-FR, Female, Microsoft Julie Mobile - French (France) Microsoft Paul Mobile, fr-FR, Male, Microsoft Paul Mobile - French (France) Microsoft Cosimo Mobile, it-IT, Male, Microsoft Cosimo Mobile - Italian (Italy) Microsoft Elsa Mobile, it-IT, Female, Microsoft Elsa Mobile - Italian (Italy) Microsoft Ayumi Mobile, ja-JP, Female, Microsoft Ayumi Mobile - Japanese (Japan) Microsoft Ichiro Mobile, ja-JP, Male, Microsoft Ichiro Mobile - Japanese (Japan) Microsoft Adam Mobile, pl-PL, Male, Microsoft Adam Mobile - Polish (Poland) Microsoft Paulina Mobile, pl-PL, Female, Microsoft Paulina Mobile - Polish (Poland) Microsoft Daniel Mobile, pt-BR, Male, Microsoft Daniel Mobile - Portuguese (Brazil) Microsoft Maria Mobile, pt-BR, Female, Microsoft Maria Mobile - Portuguese (Brazil) Microsoft Irina Mobile, ru-RU, Female, Microsoft Irina Mobile - Russian (Russia) Microsoft Pavel Mobile, ru-RU, Male, Microsoft Pavel Mobile - Russian (Russia) Microsoft Kangkang Mobile, zh-CN, Male, Microsoft Kangkang Mobile - Chinese (Simplified, PRC) Microsoft Yaoyao Mobile, zh-CN, Female, Microsoft Yaoyao Mobile - Chinese (Simplified, PRC) Microsoft Danny Mobile, zh-HK, Male, Microsoft Danny Mobile - Chinese (Traditional, Hong Kong S.A.R.) Microsoft Tracy Mobile, zh-HK, Female, Microsoft Tracy Mobile - Chinese (Traditional, Hong Kong S.A.R.) Microsoft Yating Mobile, zh-TW, Female, Microsoft Yating Mobile - Chinese (Traditional, Taiwan) Microsoft Zhiwei Mobile, zh-TW, Male, Microsoft Zhiwei Mobile - Chinese (Traditional, Taiwan)

For more fine-grained control of text-to-speech you can use the SSML format to optimise speech and make it sound authentically human. Use the sample SSML from the W3C website:

private async void TTS_SSML(object sender, RoutedEventArgs e) {     var text2speech = new SpeechSynthesizer();     await text2speech.SpeakSsmlAsync(@"<speak version=""1.0""         xmlns=""http://www.w3.org/2001/10/synthesis"" xml:lang=""en-US"">         <voice gender=""female"">         Hi, this is Justin's computer...         </voice>         <voice age=""6"">         Hello <prosody contour=""(0%,+20Hz)(10%,+30%)(40%,+10Hz)"">world</prosody>         </voice>     </speak>"); }

Run this sample you'll hear this audio: The media player is loading...

Speech: Speech to text

Speech to text used to be quite hard to do successfully. Even the best hacked-up solutions in WP7 apps were flaky and the technology never caught on with consumers. In Windows Phone 8, Microsoft has really taken the lead and created a top notch speech to text API. Most of the processing happens on a remote server, so you will need a data connection for it to work.

The following code is a simple speech to text recognising session running directly from the UI.

private async void STT_Freeform(object sender, RoutedEventArgs e) {     SpeechRecognizerUI speechRecognizer = new SpeechRecognizerUI();     speechRecognizer.Settings.ExampleText = "Fine thanks";     speechRecognizer.Settings.ListenText = "How's it goin', eh?";     speechRecognizer.Settings.ReadoutEnabled = true;     speechRecognizer.Settings.ShowConfirmation = true;     SpeechRecognitionUIResult result = await speechRecognizer.RecognizeWithUIAsync();     if (result.ResultStatus == SpeechRecognitionUIStatus.Succeeded)     {         MessageBox.Show(result.RecognitionResult.Text);     } }


The code snippet behaves as shown in the following video: The media player is loading...

One useful feature, that helps improve recognition accuracy further is that you can limit the supported answers by loading in a grammar from a list or from a file, as follows:

private async void STT_FromList(object sender, RoutedEventArgs e) {     SpeechRecognizerUI speechRecognizer = new SpeechRecognizerUI();     speechRecognizer.Settings.ExampleText = "Me, You, Everyone";     speechRecognizer.Settings.ListenText = "Who's awesome?";     speechRecognizer.Settings.ReadoutEnabled = true;     speechRecognizer.Settings.ShowConfirmation = true; ?     speechRecognizer.Recognizer.Grammars.AddGrammarFromList("answer",         new string[] { "You", "Me", "Everyone" }); ?     SpeechRecognitionUIResult result = await speechRecognizer.RecognizeWithUIAsync();     if (result.ResultStatus == SpeechRecognitionUIStatus.Succeeded)     {         MessageBox.Show(result.RecognitionResult.Text);     } }

Now when you run the code the system recognises only words from the grammar list.

It's also possible to perform a speech-to-text conversion without showing a UI. For example, this code snippet will analyse any audio file:

private async void STT_NonVisual(object sender, RoutedEventArgs e) {     SpeechRecognizer speechRecognizer = new SpeechRecognizer();       SpeechRecognitionResult result = await speechRecognizer.RecognizeAsync();     MessageBox.Show("Heard \"" + result.Text + "\" with a confidence of " + result.TextConfidence); }

And you can see that the engine can cope with even my quaint Canadian accent (video here).

WP8 Voice Recognition confirming spoken text dictation

The media player is loading...

Speech: Voice Commands

Apps can now register voice commands that could either wake up the app or be used from within the app. Each voice command can be broken down into three pieces: the app name, the command and its phrase list.

Breaking down Voice command structure: app name, command and phrases

When building voice commands you'll need to start out by creating a VCD (Voice Command Definition) file. For a simple voice command, create this simple VCD that'll demonstrate using all three elements of the command.

<?xml version="1.0" encoding="utf-8"?> <VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.0">   <CommandSet xml:lang="en-us"> ?     <Example>Compute Pii to a billion places</Example> ?     <Command Name="ComputePii">       <Example>Compute Pii to a billion places</Example>       <ListenFor>Compute Pii to a {number} places</ListenFor>       <ListenFor>Compute Pii NOW</ListenFor>       <Feedback>Computing Pii...</Feedback>       <Navigate Target="MainPage.xaml"/>     </Command> ?     <PhraseList Label="number">       <Item>one</Item>       <Item>two</Item>       <Item>billion</Item>     </PhraseList> ?   </CommandSet> </VoiceCommands>

As you can see, the purpose of this file is to define a command that's wired up to a Target URI deeplink and lists the phrases that command can use.

Note:?You may wonder why the VCD doesn't include ?My App?. This is because the app name is derived from the information provided in the WmAppManfiest file. After the app has been submitted to the WP8 store, Dev Center overrides this information with the app name as it's shown in the Windows Phone 8 store.

Next, you'll have to register this file with the OS so that it knows to recognise the voice commands. Preferably this is done on app start-up and only once, but in this example you can simply register the XML in an event handler.

private async void VoiceCommands(object sender, RoutedEventArgs e) {     await VoiceCommandService.InstallCommandSetsFromFileAsync(             new Uri("file://" +                 Windows.ApplicationModel.Package.Current.InstalledLocation.Path +                 @"/ComputePiiVCD.xml",                 UriKind.RelativeOrAbsolute));     MessageBox.Show(@"Hit the home key to go to the start screen. Then press and hold the Windows button and say: My App, Compute Pii to a Billion Places",                     "Voice Commands registered.",                     MessageBoxButton.OK); }

Finally, you'll have to handle the event when a voice command invokes the app. Do that by overriding the OnNavigatedTo handler and show a MessageBox with all the URI querystring parameters. Note, a real-world implementation would be to create your own UriMapper and use that to navigate the user to the right page.

protected async override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {     base.OnNavigatedTo(e);     if (NavigationContext.QueryString.Any())     {         StringBuilder sb = new StringBuilder();         foreach (var key in NavigationContext.QueryString.Keys)         {             sb.AppendLine(key + ": " + NavigationContext.QueryString[key]);         }         MessageBox.Show(sb.ToString(), "Page Querystring", MessageBoxButton.OK);     } }

Finally you run the app, register the commands, go to the home screen, and then say "My App, Compute Pi to a Billion places".

You can download the video showing the speech commands in action or watch it below: The media player is loading...

Lock Screen: Background image, counter, and text

As part of Windows Phone 8 users can hand over control of the lock screen appearance to apps. Specifically, apps can change the lock screen background image, the five counters on the bottom and the text displayed on the home screen. In Windows Phone 7 the image had to have been specified by the user, the text must be the next meeting in outlook and only system apps could be counters. So this is a big step up in OS customization.

Sample lock screen with background image, text and counters

To start you declare a lock screen extension so your app will show up in the settings screens. Add the following code to WmAppManfiest.xml immediately after the <Tokens /> element:

<Extensions>   <Extension ExtensionName="LockScreen_Notification_IconCount"              ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />   <Extension ExtensionName="LockScreen_Notification_TextField"              ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />   <Extension ExtensionName="LockScreen_Wallpaper"              ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" /> </Extensions>

Specify a 24x24 pixel transparent PNG file with some white pixels too, for the app's counter icon.

<DeviceLockImageURI IsRelative="true" IsResource="false">24x24.png</DeviceLockImageURI>

Now users can see the app in the Lock Screen Settings and choose to let the app change the lock screen.

Instead of using the Settings screen, the user can opt-in to the app supplying lock screen images. You add this feature with:

private async void LockScreen_ChangeImage(object sender, RoutedEventArgs e) {     if (!LockScreenManager.IsProvidedByCurrentApplication)     {         await LockScreenManager.RequestAccessAsync();     } }

Running the code you see the app ask the user to give permission for the app to provide wallpaper images to the lock screen.

Dialog requesting permission to use app for lock screen.

Now the app can change the lock screen background image, as follows:

private async void LockScreen_ChangeImage(object sender, RoutedEventArgs e) {     if (!LockScreenManager.IsProvidedByCurrentApplication)     {         await LockScreenManager.RequestAccessAsync();     } ?     if (LockScreenManager.IsProvidedByCurrentApplication)     {         LockScreen.SetImageUri(             new Uri("ms-appx:///CustomizedPersonalWalleper.jpg", UriKind.RelativeOrAbsolute));     }     MessageBox.Show("Lock screen changed. Click F12 or go to lock screen."); }

Running the app you will see the new image is the lock screen background image. The background image can be anything you'd like it to be and can be composed dynamically.

You can add text and a counter to the lock screen as well, by assigning values to the app's pinned tile.

private void LockScreen_ChangeCounterAndText(object sender, RoutedEventArgs e) {     ShellTile.ActiveTiles.First().Update(         new FlipTileData()         {         Count = 99,         WideBackContent = "Lock screen text",         SmallBackgroundImage = new Uri(@"Assets\Tiles\FlipCycleTileSmall.png", UriKind.Relative),         BackgroundImage = new Uri(@"Assets\Tiles\FlipCycleTileMedium.png", UriKind.Relative),         BackBackgroundImage = new Uri(@"Assets\Tiles\FlipCycleTileMedium.png", UriKind.Relative)         }); }

This results in the following lock screen:

Lock screen with custom counter, icon and text

Live Tiles: New sizes and new templates

The Windows Phone 8 home screen has been redesigned so that apps can have normal, wide, and small tiles. You can set these templates for your app as part of the WmAppManfiest XML PrimaryToken, by updating the TileData in code, and using push notifications template XML. In this article the WmAppManifest syntax are explored.


Flip Template

In Mango the StandardTileData class was introduced, FlipTileData is the equivalent of that class in WP8 but with new properties. TemplateFlip has flip content on both sizes of the tile and supports all the new tile sizes.

TemplateFlip properties overview

You specify flip tiles by specifying a PrimaryToken as ?FlipTemplate? or using the FlipData class from code. Here is an example using the FlipTemplate XML.

<PrimaryToken TokenID="WP8_Beta_22Token" TaskName="_default">   <TemplateFlip>     <SmallImageURI IsRelative="true" IsResource="false">159x159.png</SmallImageURI>     <Count>5</Count>     <BackgroundImageURI IsRelative="true" IsResource="false">336x336.png</BackgroundImageURI>     <Title>Title</Title>     <BackContent>Back Content</BackContent>     <BackBackgroundImageURI IsRelative="true" IsResource="false">336x336.png</BackBackgroundImageURI>     <BackTitle>Back Title</BackTitle>     <LargeBackgroundImageURI IsRelative="true" IsResource="false">691x336.png</LargeBackgroundImageURI>     <LargeBackContent>Hello World</LargeBackContent>     <LargeBackBackgroundImageURI IsRelative="true" IsResource="false">691x336.png</LargeBackBackgroundImageURI>     <DeviceLockImageURI IsRelative="true" IsResource="false">24x24.png</DeviceLockImageURI>     <HasLarge>True</HasLarge>   </TemplateFlip> </PrimaryToken>

The example below shows the same tile, five times to display all the tiles sizes and show back and front content.

TemplateFlip with small, normal and large tiles


Iconic Template

One of the most common uses of tiles in WP7 is to recreate the look of the built-in apps' tiles. It was such a common use case that third-party projects, such as MSP Toolkit, stepped in to fill the gap. The good news is that Windows Phone 8 provides built-in support for tile templates that look similar to native live tiles. The various properties that can be set on this new type of template are shown below:

TemplateIconic properties overview

You use the TemplateIconic XML in the WmAppManifest file or the IconicTileData class to specify the content. This example uses the TemplateIconic:

<PrimaryToken TokenID="WP8_Beta_22Token" TaskName="_default">   <TemplateIconic>     <SmallImageURI IsRelative="true" IsResource="false">110x110.png</SmallImageURI>     <Count>5</Count>     <IconImageURI IsRelative="true" IsResource="false">202x202.png</IconImageURI>     <Title>Title</Title>     <Message>Message</Message><

Source: http://www.developer.nokia.com/Community/Wiki/index.php?title=What's_new_in_Windows_Phone_8&diff=177337&oldid=176707

buffalo sabres texas news kim mulkey sarah palin today show dallas tornado video 1940 census instagram for android

No comments:

Post a Comment