Windows Phone – Reactive Extensions (Rx)

In my previous post I talked about how important it is to use page transitions and animations in your application to increase the overall user experience. Wouldn’t it be nice if we could extend this experience a bit, and take it to the next level of user feedback and interaction.

Fortunately there is a framework called Reactive Extensions (Rx) that enables us to do all kinds of super cool stuff in our applications.

This post will show how easy it is to use the Reactive Extensions framework to increase the user experience when loading data from services and showing it to the user in a more elegant way.

Reactive Extensions (Rx)

First of all, Reactive Extensions is a library to compose asynchronous and event-based programs using observable collections and LINQ-style query operators. You can start learning about Rx at MSDN if this is new to you: http://msdn.microsoft.com/en-us/data/gg577609

In the sample project that I’m going to build, I will simulate a call to a web service to fetch data, and when data is returned I will populate a ListBox with the data. The items will be added one by one to the list with a nice subtle animations to give feedback to the user that items are being added to the list. I will simulate fetching from different services and add them result items to the list as soon as they arrive.

1. Create the Phone project

You start by creating a Windows Phone 7.1 project using the “Windows Phone Databound Application” template.

This will give you all the needed UI automatically, we will just refactor it and change so that it uses loading animations and Reactive Extensions when displaying the items to the user.

2. Change the UI

Now let’s change the Item Template for the ListBox so that each row has a solid background color (will be easier to see the animation) and finally add an animation/storyboard that is executed when a row is loaded (using event trigger).

The final ItemTemplate:

    <DataTemplate>
        <Grid x:Name="TileGrid">
            <Grid.Triggers>
                <EventTrigger RoutedEvent="Grid.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation 
                                Storyboard.TargetName="TileGrid"
                                Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)"
                                Duration="0:0:0.5" To="0" />
                            <DoubleAnimation
                                Storyboard.TargetName="TileGrid"
                                Storyboard.TargetProperty="Opacity"
                                Duration="0:0:0.5" To="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Grid.Triggers>
            <StackPanel Margin="0,0,0,17" Width="432" Height="78" Background="{StaticResource PhoneAccentBrush}">
                <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
            </StackPanel>
            <Grid.Projection>
                <PlaneProjection CenterOfRotationX="0" CenterOfRotationY="0"
                        RotationY="-90" />
            </Grid.Projection>
        </Grid>
    </DataTemplate>

If we run the application now, we already see an animation for the loaded event.

But all items are loaded at the same time. What if we wanted each row to be loaded one by one with a 200 millisecond delay? How would we do that?
One option is to use a background worker that has a 200 millisecond sleep in each loop that adds an item to the Items collection that is used as ItemsSource on the ListBox.
Let’s try that and see how it would look like and then later simplify the source code using Reactive Extensions.

3. Add item loaded delays
Start by refactoring the MainViewModel.cs LoadData() method to hold the sample data in a temporary list (so that we can use that list in our background worker to finally add them one by one to the Items collection)
Hint: to change the source code on multiple rows at the same time, you can hold down the Alt key while highlighting text in the editor to select parts of the text on multiple rows and then type on your keyboard to change the text on multiple rows at the same time. Realy nice feature :)

The final source code with BackgroundWorker:

    public void LoadData()
    {
        // Temporary hold the items in memory
        ObservableCollection<ItemViewModel> items = new ObservableCollection<ItemViewModel>();

        // Sample data; replace with real data
        items.Add(new ItemViewModel() { LineOne = "runtime one", ... });
        items.Add(new ItemViewModel() { LineOne = "runtime two", ... });
        items.Add(new ItemViewModel() { LineOne = "runtime three", ... });
        ...
        items.Add(new ItemViewModel() { LineOne = "runtime sixteen", ... });

        this.IsDataLoaded = true;

        // Create background worker that adds all items to the Items collection with delays
        var worker = new BackgroundWorker();
        worker.DoWork += delegate(object sender, DoWorkEventArgs args)
        {
            // Loop through all the items
            for (int i = 0; i < items.Count - 1; i++)
            {
                // Create a slight delay and add each item to the Items collection
                Thread.Sleep(200);
                Deployment.Current.Dispatcher.BeginInvoke(
                    () =>
                    {
                        Items.Add(items[i]);
                    });
            }
        };
        worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs args)
        {
        };
        worker.RunWorkerAsync();
    }

If we run the application now we have a nice animation for each row when they are added to the Items collection

4. Add Reactive Extensions (Rx)
So the above use of background worker is working just fine, but can we simplify the source code using Rx?
First of all to use Rx you need to add the following references to the project

  • Microsoft.Phone.Reactive
  • System.Observable

and the following using statements

    using Microsoft.Phone.Reactive;
    using System.Linq;

Then finally remove the Background Worker code section and replace with the following code and also add the method AddItem

    public void LoadData()
    {
    
    ....

    // Convert the result to an Observable sequence
    items.ToObservable()
        // Add selector method that selects each item with 200 ms delay
        .Zip(Observable.Interval(TimeSpan.FromMilliseconds(200)), (d, t) => d)
        // asyncrounously notify observers using the current dispatcher
        .ObserveOnDispatcher()
        // subscribe a value handler to an observable sequence
        .Subscribe(AddItem); 
    }

    private void AddItem(ItemViewModel item)
    {
        Items.Add(item);
    }

If we run the application now we have the same result as expected. Although the source code is now a lot nicer, and we don’t have to worry about cross thread issues, index out of bound when looping through the items etc. This is just a really simple useage of Rx framework, but there is a lot more cool stuff you can do with it. Perhaps I’ll write a post later on a more complicated scenario.

Performance

You should always pay attention to performance on the phone when using animations and transitions. If we enable draw regions we can see that during loading the list box items are redrawn several times, although this is OK in this simple application but something to pay attention to.

    // Show the areas of the app that are being redrawn in each frame.
    Application.Current.Host.Settings.EnableRedrawRegions = true;

Happy Coding!

Windows Phone – Animations and Transitions

Microsoft is introducing a fresh approach on UI design and user experiences based on the Metro design language and principles. Even though you follow the Metro design guidelines you are according to me only half-way there to a perfect design and user experience. If you think about all the out of the box experiences on the phone you realize that they feel a lot more alive than most of the apps you download from the marketplace. How is that? The simple answer is user experience through transitions and animations. Animations and transitions on the Windows Phone platform are fundamental elements that are deeply rooted in the UI concept.

Animations and Transitions

Animations is probably one of the most important features of Windows Phone. Most developers and customers I have talked to in the past tend to see animations as something extra fancy that you don’t need in an application, especially not in a LOB (line of business) application. I would argue and say that they are as important in a LOB app as in any other app.

Animations and transitions extends the user experience by giving subtle feedback to the user on what is going on, what is happening and to what is about to happen. It increases the overall experience.

A lot of applications are really static, no specific feedback to the user for any actions they perform, transition between pages and so on. The apps would feel much more polished and alive if the designers would spend time on creating subtle proper animations and transitions.

The Silverlight toolkit makes page transitions and user feedback super easy to implement. But be careful, overdoing animations will only annoy the users and detract the user experience.

Let’s go through how simple it is to add page transitions to your application.

  • First of all you need to install the Windows Phone Toolkit
  • add a reference to Microsoft.Phone.Controls.Toolkit to your project
  • in App.xaml.cs locate the InitializePhoneApplication method and change the RootFrame from a regular PhoneApplicationFrame to a TransitionFrame
        RootFrame = new Microsoft.Phone.Controls.TransitionFrame();
    
  • you have now prepared your application to use any of the page transitions provided by the toolkit.
  • finally add a page transition to your page. Either add xaml code to each page (which eventually leads to a lot of copy-paste) or create a Style that you reference in each page.

Xaml in each page

Start by creating a name space to the Windows Phone Toolkit

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

add the following xaml to the page. This example uses the Turnstile transition. A good sample application that shows all the different page transitions is found at codeplex: http://pagetransitions.codeplex.com/

<phone:PhoneApplicationPage
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
… >
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

Better approach with Styles

To make the transitions easier to maintain, and easier to switch between different page transitions when trying out your application, I would suggest you to create a style resource for each different page transition you want to use.

    <!--Application Resources-->
    <Application.Resources>
        <Style x:Key="TurnstilePage" TargetType="phone:PhoneApplicationPage">
            <Setter Property="toolkit:TransitionService.NavigationInTransition">
                <Setter.Value>
                    <toolkit:NavigationInTransition>
                        <toolkit:NavigationInTransition.Backward>
                            <toolkit:TurnstileTransition Mode="BackwardIn"/>
                        </toolkit:NavigationInTransition.Backward>
                        <toolkit:NavigationInTransition.Forward>
                            <toolkit:TurnstileTransition Mode="ForwardIn"/>
                        </toolkit:NavigationInTransition.Forward>
                    </toolkit:NavigationInTransition>
                </Setter.Value>
            </Setter>
            <Setter Property="toolkit:TransitionService.NavigationOutTransition">
                <Setter.Value>
                    <toolkit:NavigationOutTransition>
                        <toolkit:NavigationOutTransition.Backward>
                            <toolkit:TurnstileTransition Mode="BackwardOut"/>
                        </toolkit:NavigationOutTransition.Backward>
                        <toolkit:NavigationOutTransition.Forward>
                            <toolkit:TurnstileTransition Mode="ForwardOut"/>
                        </toolkit:NavigationOutTransition.Forward>
                    </toolkit:NavigationOutTransition>
                </Setter.Value>
            </Setter>
        </Style>
    </Application.Resources>

Then in each page where you want to use a page transition (note that we could omit x:Key to make this an implicit style and default for all pages) you simply reference the wanted page style in the following way

<phone:PhoneApplicationPage Style="{StaticResource TurnstilePage}" ... >

Enhance user actions with visual feedback

It’s also a good practice to add feedback to the user when he or she presses a button or selects an item in a list that performs an action. This can easily be done by using the Tilt Effect.

Conclusions

Adding page transitions to your app is really simple and increases the user experience a lot, but as noted before, be careful, overdoing animations and transitions will make your app annoying and potentially get really bad ratings.

Happy Coding!

Windows Phone Mango – Multiple Emulators


I just realized that I need to have two emulators running at the same times since I’m developing a socket demo where two phones are talking to each other. Fortunately there is a way to have two emulators running while debugging at the same time. So if you are developing any multi-client application and need two instances of the emulator, this post will guide you on how to do that.

  1. Open the Windows Explorer and browse to C:\ProgramData\Microsoft\Phone Tools\CoreCon\10.0\addons
  2. Create a copy of the file “ImageConfig.en-US.xsl”, you can name it as you want, I just did a copy/paste and ended up with “ImageConfig.en-US – Copy.xsl”
  3. Find and edit the following in the new copy:
    • In the <DEVICE> element, change the Name attribute to “Windows Phone Emulator Instance 2”
    • Also change the ID attribute to a new GUID in the same element. You can create a new GUID here or just make one up
    • In the <PROPERTY ID=”VMID” Protected=”false”> element, change the value to the same GUID as you specified above and make sure you preserve the braces {}

That’s it, now restart Visual Studio if you have it running and you will now have two Emulators to use!

Happy Coding!

Windows Phone Mango – Encrypt Data

Windows Phone 7 Mango has focused on the end consumer market. The phrase “Put people first” is something we have seen in all of Microsoft’s Windows Phone 7 Mango promotions. The market place is filling up with apps targeting the common user, so for most applications encryption has not been super important, although more and more enterprise apps and data sensitive apps are coming and protecting your data is key in many scenarios.

Saving data in a phone’s isolated storage is not secure, there is a tool that comes with the SDK that enables you to list, copy and replace files and directories in isolated storage. You can read about how to use the tool at MSDN. There is an excellent tool that allows the developers to do a lot more with their applications, like uninstalling developer XAPs, get detailed device information, browse the Isolated Storage, copy phones local SQL CE DB to your PC to extract and change data and so on, all this through a really nice UI. Get your hands on the Windows Phone Power Tools at CodePlex.

image

This article will go through the basics in how you encrypt/decrypt sensitive and confidential data such as username, password, PIN code etc. using the Data Protection API (DPAPI) to prevent anyone from accessing your data using tools like the isolated storage explorer.

DPAPI

Encrypting the data will not increase the security if the decryption key resides on the phone, no matter how well the key is hidden. DPAPI solves the problem of explicitly generating and storing a cryptographic key by using the user and phone credentials to encrypt and decrypt data.  This means that the only place where you can decrypt your encrypted data is on the phone itself !

ProtectedData class

You can use the ProtectedData class that provides you access to DPAPI through Protect and Unprotect methods. On a Windows Phone device, every application gets its own decryption key when the application executes for the first time. Calls to Protect and Unprotect methods will implicitly use the decryption key and make sure all data remains secure and private to the application.

Protect – Use this method to encrypt your data
Unprotect – Use this method to decrypt your data

I have created a CryptoUtils class that enables you to encrypt and decrypt strings to isolated storage.

 public static class CryptoUtil
    {
        /// <summary>
        /// Encrypt a string and store it in the phone's isolated storage
        /// </summary>
        /// <param name="value"></param>
        /// <param name="path"></param>
        public static void EncryptAndStore(string value, string path)
        {
            // Convert the string to a byte[].
            byte[] PinByte = Encoding.UTF8.GetBytes(value);

            // Encrypt the string by using the Protect() method.
            byte[] ProtectedBytes = ProtectedData.Protect(PinByte, null);

            // Store the encrypted string in isolated storage.
            CryptoUtil.WriteProtectedStringToFile(ProtectedBytes, path);

        }

        /// <summary>
        /// Decrypt a string that is stored in the phone's isolated storage in the provided path
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string DecryptString(string path)
        {
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!file.FileExists(path)) return string.Empty;
            }
            // Retrieve the string from isolated storage.
            byte[] ProtectedPinByte = CryptoUtil.ReadStringFromFile(path);

            // Decrypt the string by using the Unprotect method.
            byte[] PinByte = ProtectedData.Unprotect(ProtectedPinByte, null);

            // Convert the PIN from byte to string and display it in the text box.
            return Encoding.UTF8.GetString(PinByte, 0, PinByte.Length);
        }

        private static void WriteProtectedStringToFile(byte[] strinData, string path)
        {
            // Create a file in the application's isolated storage.
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream writestream = new IsolatedStorageFileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write, file);

                // Write stringData to the file.
                Stream writer = new StreamWriter(writestream).BaseStream;
                writer.Write(strinData, 0, strinData.Length);
                writer.Close();
                writestream.Close();
            }
        }

        private static byte[] ReadStringFromFile(string path)
        {
            // Access the file in the application's isolated storage.
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream readstream = new IsolatedStorageFileStream(path, System.IO.FileMode.Open, FileAccess.Read, file);

                // Read the PIN from the file.
                Stream reader = new StreamReader(readstream).BaseStream;
                byte[] pinArray = new byte[reader.Length];

                reader.Read(pinArray, 0, pinArray.Length);
                reader.Close();
                readstream.Close();

                return pinArray;
            }
        }
    }

Conclusions

It is really easy to use DPAPI with Protect and Unprotect methods and if you create a CryptoUtils class that can be easily used in all of your applications there is no excuses not to do it :)

Note: If you want to encrypt large amount of data and the data is stored in the local database on the phone, then encrypting the entire database is a better options. See my next post about encypting Local DB.

Happy Coding!!

Windows Phone Mango – Background Agents

There is often the need of executing code in the background while your application is not in the foreground. You might want to synchronize data through WCF or just simply alert the user of something. In Windows Phone Mango we have “multitasking” in the sense that scheduled tasks and background agents allow an application to execute code. This is however not a true multitasking feature since there are limits on how often and how long each task man run.

An application may only have one background agent registered and capable of performing periodic tasks, and/or resource intensive tasks. Depending on what type of task you implement they will be scheduled differently.

Let’s start by explaining the different tasks and when to use them, and then follow up on how you actually implement background agents.

PeriodicTask

Periodic agents run for a small amount of time (typically for 25 seconds) on regular reoccurring intervals (typically every 30 minutes). Use this type to do small tasks, small data synchronizations etc.

ResourceIntensiveTask

Resource intensive agents run for a relatively long period (typically 10 minutes), although only when certain constraints are met:

  • External power required
  • Non-Cellular connection required (needs Wi-Fi connection or through PC connection)
  • Minimum battery power (needs to be greater than 90%)
  • Device screen lock required (device screen needs to be locked)
  • No active phone call
  • Cannot change network to cellular

As we see there are a lot of constraints that needs to be met for resource intensive tasks to be executed, so most applications will only use period tasks.

Unsupported APIs

There are also a lot of APIs that you cannot use when executing code in a background agent. Take a look at the MSDN page for details: http://msdn.microsoft.com/en-us/library/hh202962%28v=VS.92%29.aspx

How to implement Background Agents

First of all you create a Windows Phone project and implement your application as usual. Next you need to add a Scheduled Task Agent project to your solution to add background agents use to your application

  1. From the File menu select Add-New Project and select Windows Phone Scheduled Task Agent project. Name the project and hit OK.
  2. Now in your Windows Phone project you need to add a project reference to the agent project.

In the Scheduled task agent project there is now a file called ScheduledAgent.cs. This file contains the source code that will be executed in the background. Add functionality to method OnIvoke() that you want to be executed, this method is called by the OS when the scheduled tasks executes.

Each application can only register one background agent, although you can implement both Periodic tasks and Resource Intensive Tasks. The below code section shows how you check task type and how to run the task more often when debugging. Since the tasks are executed each 30 min, it would be cumbersome to test your application if that period could not be adjusted. Luckily you can set that during debugging by calling ScheduledActionService.LaunchForTest() method.


protected override void OnInvoke(ScheduledTask task)
{

//TODO: Add code to perform your task in background

// If your application uses both PeriodicTask and ResourceIntensiveTask
// you can branch your application code here. Otherwise, you don't need to.
if (task is PeriodicTask)
{
// Execute periodic task actions here.
}
else
{
// Execute resource-intensive task actions here.
}

// If debugging is enabled, launch the agent again in one minute.
#if DEBUG_AGENT
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
#endif

// Call NotifyComplete to let the system know the agent is done working.
NotifyComplete();
}

Now to actually use background agents we have to register and add a background agent in our foreground application. This is also fairly straightforward to accomplish. You simply create either a PeriodicTask object or ResourceIntensiveTask object and add them to the ScheduledActionService.

Create PeriodicTask

PeriodicTask periodicTask;
string periodicTaskName = "PeriodicAgent";

private void StartPeriodicAgent()
{
  // Obtain a reference to the period task, if one exists
  periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

  // If the task already exists and background agents are enabled for the
  // application, you must remove the task and then add it again to update
  // the schedule
  if (periodicTask != null)
  {
    RemoveAgent(periodicTaskName);
  }

  periodicTask = new PeriodicTask(periodicTaskName);

  // The description is required for periodic agents. This is the string that the user
  // will see in the background services Settings page on the device.
  periodicTask.Description = "This demonstrates a periodic task.";

  // Place the call to Add in a try block in case the user has disabled agents.
  try
  {
    ScheduledActionService.Add(periodicTask);
    PeriodicStackPanel.DataContext = periodicTask;

    // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if(DEBUG_AGENT)
    ScheduledActionService.LaunchForTest(periodicTaskName, TimeSpan.FromSeconds(60));
#endif
  }
  catch (InvalidOperationException exception)
  {
    if (exception.Message.Contains("BNS Error: The action is disabled"))
    {
      MessageBox.Show("Background agents for this application have been disabled by the user.");
    }
  }
}

Create ResourceIntesiveTask

ResourceIntensiveTask resourceIntensiveTask;
string resourceIntensiveTaskName = "ResourceIntensiveAgent";

private void StartResourceIntensiveAgent()
{
  resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask;

  // If the task already exists and background agents are enabled for the
  // application, you must remove the task and then add it again to update 
  // the schedule
  if (resourceIntensiveTask != null)
  {
    RemoveAgent(resourceIntensiveTaskName);
  }

  resourceIntensiveTask = new ResourceIntensiveTask(resourceIntensiveTaskName);

  // The description is required for periodic agents. This is the string that the user
  // will see in the background services Settings page on the device.
  resourceIntensiveTask.Description = "This demonstrates a resource-intensive task.";

  // Place the call to Add in a try block in case the user has disabled agents
  try
  {
    ScheduledActionService.Add(resourceIntensiveTask);
    ResourceIntensiveStackPanel.DataContext = resourceIntensiveTask;

    // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
#if(DEBUG_AGENT)
    ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(60));
#endif
  }
  catch (InvalidOperationException exception)
  {
    if (exception.Message.Contains("BNS Error: The action is disabled"))
    {
      MessageBox.Show("Background agents for this application have been disabled by the user.");
    }
  }
}

That’s all there is to it. Pretty simple and straightforward to implement.

In the OnInvoke() method you can call WCF services, do simple synchronizations and store data in Isolated Storage or the local SQL DB or what ever fits you needs. One thing that I have not figured out yet is if it is possible to alert the foreground application that data has changed and that it needs to refresh data from, for example, Isolated Storage.

Happy coding!

Windows 8 Developer Preview – VirtualBox

I had a lot of small issues when installing Windows 8 as a Virtual Machine (I know, no touch.. although want to quickly start playing with it). I could not access the Internet, I could not set the screen resolution to 1920×1080 etc etc.. But I finally found this blog post that really helped me solve all my issues!

If you have any problems running Windows 8 as a virtual machine, I suggest you take a look at the follow blog post!

http://www.pitorque.de/MisterGoodcat/post/Installing-Windows-8-Developer-Preview-in-a-virtual-machine.aspx

Happy Windows 8 Metro Application Coding!

Windows Phone Mango – Tombstoning XNA

It struck me that tombstoning when building a XNA application has to be somewhat different then tombstoning a regular Windows Phone Silverlight application. I was thinking of the “Pause screen”, Guide Dialogs (these have to halt the game in some way) etc. Also the events are triggered at different occasions in an XNA application then in a Silverlight application. In Windows Phone Mango you can also mix Silverlight/XNA, are there any special actions needed for application life cycle and tombstoning in these cases?

Let’s go through how tombstoning in XNA applications work and what the differences are compared to a regular Windows Phone Silverlight application.

Read more

Lär dig presentera som mästarnas mästare

Gurun Richard Klees till Sverige
Lär dig att övertyga din chef, dina kunder eller andra i din omgivning! Kom och lyssna till en helt magisk presentation med Richard Klees, som har tränat några av de bästa föreläsarna i världen. Detta seminarium är ett måste för dig som skall föreläsa på stora konferenser så som t ex Best of MMS, eller TechDays – men även för dig som vill utvecklas personligt och förbättra dina möjligheter på arbetsmarknaden.

› Stockholm (29 september)

Mer information och anmälan »

Richard Klees own Invitation:

We can feel and demonstrate confidence, professionalism and conviction when we are comfortable, feeling well, know our content inside and out, and the stakes for being successful are not so high that the pressure to do well isn’t so great. If we had a good night’s sleep and the audience is a manageable size made up of people we know and feel calm, we can do a good job.

But what happens when life is not going as well as we planned?

  • We’re nervous
  • We didn’t get a chance to prepare as thoroughly as we would have liked
  • We must be successful because our boss is counting on us to do well
  • We are jet-lagged or fighting a cold, and just don’t feel well-rested
  • We are presenting to a larger audience than we are used to and they are complete strangers
  • We feel pressure to do well and so we are constantly self-evaluating, even as we speak
  • What’s at stake could mean the difference between moving ahead and staying in the same place
  • WHAT DO YOU DO?

We would always like life to play fair, but it doesn’t. That’s where this seminar and “The Action Effect” come in. This seminar will show you how to be confident, compelling and persuasive under any circumstances, with any audience, anywhere, anytime, anyplace. That’s a big promise, but this seminar can deliver and you will see it before your eyes. Hope to see you there.

- Richard Klees

Windows Phone Mango – Tombstoning and life cycle

Before Mango the Windows Phone application could be in four states, Running, Deactivate, Tombstoned and Activate. In Mango there is a new state called Dormant. This extra state is there to provide us with fast app switching. It is important for the developer to understand the Windows Phone application life cycle and to understand what actions the developer needs to take at each state and event to provide an application that is responsive and provides a consistent experience.

The following overview explains the life cycle of Windows Phone applications and all the actions the developer should take and be aware of.

Windows Phone Life Cycle - Image taken from MSDN

Read more

Windows Phone Mango – Local Database

With the Mango update for Windows Phone we can now use a local database to store relational data. The local database in Mango is a SQL Compact Edition and you can use object models for CRUD (Create-Read-Update-Delete) operations and you have to use LINQ to SQL to query, filter and sort the data (currently T-SQL queries are not supported).

The local database is stored in the applications isolated storage. This means that the local database is sandboxed from other applications and only your application and background agents have access to the database.

Using the local database in Mango is perfect if you have relational data like Customers and Orders. It will offer you the ability to do quick, efficient and complex queries to the database using LINQ to SQL and it also allows “lazy loading” so that only the data that is necessary at a particular moment is loaded into memory.

Let’s go over the core concepts you need to know to start working with the local database for Windows Phone

Read more

Follow

Get every new post delivered to your Inbox.