Demo code and ppt deck from my Techdays talk on WP7 Push notifications, Live tiles and background agents available

It’s they day after the Techdays 2012 in the Netherlands and everyone is fully inspired by all the new knowledge they acquired at the event. I got questions from people asking for the powerpoint deck and my demo code so I told them I would upload it here. I had 2 sessions on the Techdays and both were on Windows Phone push notifications and live tiles. The session on the Geeknight was an introduction level session and in the session on Friday I showed all the details on how to use them with lots of code.

techdays_logo_2

The PowerPoint deck from my geeknight session on push notifications and livetiles  is available here: Download or View PPT

The PowerPoint deck from the level 300 Push notifications, live tiles and background agents session is available here: Download or View PPT

In both sessions I used the same demo project that can be downloaded here: Download ZIP file

My session that was held on Friday was also filmed for Channel 9. I’ll add a link to the video when it’s uploaded there.

If you have any questions on implementing push notifications, live tiles or background agents send me a tweet on @geertvdc or comment on this post.

Happy Coding

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

TechdaysNL 2012 Lots of WP7, Win8, Metro and ASP.NET MVC sessions. Which sessions to pick?

This thursday Microsoft Techdays 2012 kicks off for Dutch developers working on the Microsoft platform. This year I’m speaking at 2 sessions on Windows Phone but I’m also going to visit other sessions during the 2 days of the conventions. Here is the schedule I made with sessions I’m planning on going to. It seems there are some really cool Windows Phone sessions but Windows 8 and ASP.NET MVC also has my interests. During the event I’ll keep you posted with updates on twitter and afterwards I’ll write my experiences in a new blogpost again. Here are the sessions I’m going to visit.

badge_speaking

Thursday February 16th

09:15 – 10:45 – Keynote

Ofcourse I’m going to visit the keynote session that kicks off the event. This year the keynote is presented by 5 speakers: Ben Riga, Brian Keller , Serge van Schie, Theo Rinsema, Bryan Agnetta

11:05 – 12:20 – What’s new in ASP.NET 4.5 + Visual Studio 11Mads Kristensen

I haven’t seen that much of asp.net 4.5 since my focus lately was on Windows Phone and Windows 8 development so I’m really curious on what Mads is going to show us here.

13:30 – 14:45 – Deep Dive into MetroBryan Agnetta

Since I already am quite up to date with Windows Phone Localization I’m skipping Ben Riga’s session on that subject (which is really important to know if you’re developing WP7 apps!) and going to widen my horizon to become a better “DeVigner” by improving my design skills in the session of Bryan Agnetta.

15:05 – 16:20 – A look at ASP.NET MVC 4Scott Guthrie

When “the Gu” is speaking on an event it’s not an option not to visit at least 1 of his sessions. I’m a big fan of ASP.NET MVC since the first technical preview but haven’t seen that much of the 4th version except for some videos from BUILD. Really looking forward on hearing what Scott has to say on this subject.

16:30 – 17:45 – Scott Guthrie UnpluggedScott Guthrie

Really looking forward on this session. Scott is a reall “Gu”ru and I’m really curios on seeing him answer questions from the audience. I have some questions for him on his vision on the future of mobile and the web. Let’s see if he can answer it :) Another session that I would like to visit but is at the same time is: Fully leverage the Microsoft application platform with BizTalk, Server AppFabric and Azure AppFabric. Ah well I’ll watch that one on channel 9 later then.

 

GeekNight

19:15 – 19:55 – Beginnen met ontwikkelen voor Windows PhoneMaarten Struys

This session is in the same room as my session that held is right after this session. Ok I’m not a starting wp7 developer but It’s good to see this session so I can adapt my session to this one if a lot of people are staying after this session for my session.

20:05 – 20:45 – Push notifications en live tilesGeert van de Cruijsen

Time to do my own session. In this session I’ll give an introduction to push notifications and live tiles in your Windows Phone applications. If you are a starting wp7 developer this is the session for you. If you are a more advanced wp7 developer come to my session on friday on the Techdays on the same subject.

20:55 – 21:35 – Stand Up Windows Phone DevelopmentFons Sonnemans

After my session Fons Sonnemans is doing the next session in the WP7 track. He’s going to build an application in 1 hour. Let’s see what he’s up to.

 

Friday February 17th

09:15 – 10:30 – Going mobile with ASP.NET MVC 4Erik van Appeldoorn

The debate on building native phone applications vs mobile web is an ongoing discussion. Let’s see what Erik can do using ASP.NET MVC4 for the mobile platform. Another session that got my attention is a session from my collegue Jesse Houwing: Code review features in TFS vNext so there is a chance I’m visiting that one instead.

10:50 – 12:05 – Building Services for Phone / Tablet using WebAPIMatt Milner

This session can be really usefull if you are planning on doing push notifications for a mobile app for example or if you just want to create an app using your own created API for your website. WebAPI is a really nice new framework by Microsoft which I don’t know that much about right now. hopefully this session will give me some good info on that.

13:15 – 14:30 – Laat je Windows Phone 7 app tot leven komen met push notifications, live tiles en background agentsGeert van de Cruijsen

It’s time again to do a presentation myself. This session will explain all the ins and outs of push notifications, live tiles and background agents in your wp7 applications. If you don’t like Windows Phone visit my colleague Christiaan Veeningen’s session: Bouw Metro apps met Javascript voor Windows 8. In our original planning I was going to do this presentation together with him but doing 3 sessions was a bit to much for me to prepare for.

14:50 – 16:05 – Windows Phone Metro Design Session End-to-EndTom Eddings, Dave Crawford

Another UX session I’m going to visit. My last project building Windows Phone applications where I worked together with Avanade UX colleagues really got me interested in the design parts so I’m exited on what Tom and Dave are going to tell us.

16:15 – 17:30 – Unit testing your Windows Phone 7 applicationsOlaf Conijn

Picking a level 400 session as the last session on a Friday a smart choice? We’ll see. I already have experience in unit testing wp7 applications but I’m sure Olaf has some really nice tips for us.

So this is my list of sessions I’m visiting at the TechDays. Please let me know which ones you are visiting in the comments

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Windows Phone 7 emulator skin switcher 1.2 released on Codeplex

Version 1.0 and 1.1 of my Windows Phone 7 emulator skin switcher were hosted on my SkyDrive but I got several requests from people to move it to Codeplex so I did that this afternoon.

From now on the latest version + source can be found on http://wp7emuskinswitcher.codeplex.com/

With the move to Codeplex I also upgraded the version to 1.2. here is the Changelog:

  • Fixed a bug where the skin switcher broke the back button of the emulator when people used certain custom skins before they used the skin switcher.
  • Added working volume, camera + power buttons on the Lumia 800 skins
  • Added a White Lumia 800 skin made by Derek Orr
  • Added a Zune HD skin made by Ben Pinkerton

phones

Enjoy!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Testing the SH WP ApplicationBar in an Multiselectlist MVVM scenario

If you’re developing for Windows Phone 7 and are using MVVM you’re probably familiar with the problem that you cannot bind the out of the box ApplicationBar because it is not a silverlight control. Since the early days of WP7 there are lots of solutions and workarounds to work with the application bar but most of them do have some (minor) downsides in using them. The application bar solutions that are used the most are probably the BindableApplicationBar from PhoneFX, another BindableApplicationBar or AppBarUtils.

Up untill now I was using the PhoneFX BindableApplicationBar but I really disliked the problem that you can’t bind the visibility property of the ApplicationBarButtons to hide or show them when you need them. A common example where you use this is in a Scenario with a MultiSelectList on a page where you want to be able to hide the “Remove” button as long as you didn’t select an item yet and hide the “Select” button when you are already in the selection mode. This week I was reading a blogpost on Windows Phone Geek about the AdvancedApplicationBar and I read that this new ApplicationBar solution did support binding the Visibility of ApplicationBarButtons so it was time to put this one to the test.

In this post I’ll walk you through my the code I produced to get a nice MultiSelectList control (from the silverlight wp7 toolkit ) working with the applicationbar without writing any codebehind. I used MVVM light for this sample so an empty MVVM light project with references added to the Silverlight Toolkit and the SH WP ApplicationBar will be my starting point.

The idea is to build an application showing a MultiSelectList with some messages that you can select and delete by using the ApplicationBarButtons just as the build in Mail application does.

Lets first start of building some of the plumbing to get this application going. We’ll create a Message Class that is going to be our Class containing the information for each message. We’ll keep this Class plain and simple:

   1: public class Message

   2: {

   3:     public string Sender { get; set; }

   4:     public DateTime Date { get; set; }

   5:     public string Content { get; set; }

   6: }

We’ll also need a property in the ViewModel to expose a list of these Messages which we can fill with dummy data and that can be bound in the MultiSelectList. We’ll create a property in the ViewModel called Messages and will fill these for this small example in the constructor of the MainViewModel.

   1: /// <summary>

   2: /// Initializes a new instance of the MainViewModel class.

   3: /// </summary>

   4: public MainViewModel()

   5: {

   6:     for (int i = 0; i < 10; i++)

   7:     {

   8:         Message m = new Message();

   9:         m.Sender = "Sender " + i.ToString();

  10:         m.Date = DateTime.Now.AddHours(i);

  11:         m.Content = "This is a sample message " + i.ToString();

  12:         Messages.Add(m);

  13:     }

  14: }

  15:  

  16: /// <summary>

  17: /// The <see cref="Messages" /> property's name.

  18: /// </summary>

  19: public const string MessagesPropertyName = "Messages";

  20:  

  21: private ObservableCollection<Message> _messages = null;

  22:  

  23: /// <summary>

  24: /// Sets and gets the Messages property.

  25: /// Changes to that property's value raise the PropertyChanged event. 

  26: /// </summary>

  27: public ObservableCollection<Message> Messages

  28: {

  29:     get

  30:     {

  31:         return _messages;

  32:     }

  33:  

  34:     set

  35:     {

  36:         if (_messages == value)

  37:         {

  38:             return;

  39:         }

  40:  

  41:         _messages = value;

  42:         RaisePropertyChanged(MessagesPropertyName);

  43:     }

  44: }

Now the data is there it’s time to create the UI. One of the best parts of using MVVM is creating the UI in Expression Blend so lets use that. We’ll add a MultiSelectList Control to the page (it’s a control that comes in the silverlight toolkit for wp7) and bind the itemsource to the Messages property. We’ll also add the AdvancedApplicationBar from the SH WP library to the page and create 2 buttons to be used on the ApplicationBar, a select button and a delete button. Set the size of the MultiSelectList to Autosize –> full and make sure the AdvancedApplicationBar control is located in the Layoutroot. Set the text of the 2 ApplicationBarButtons to Select and Remove and also select an image for the buttons.

multiselectlist

When you rebuild now you’ll see 10 lines of code in the multiselect list. Change the ItemTemplate for the MultiSelectList by creating an empty template and adding 3 textboxes to them binding them to our 3 fields in our Message Class: Sender, Date and Content. Give all of them a pretty style and we’re ready to go on.

itemtemplate

Your Xaml for the contentgrid should look like this

   1: <Grid x:Name="ContentGrid"

   2:       Grid.Row="1" Height="537" VerticalAlignment="Top">

   3:     <toolkit:MultiselectList ItemsSource="{Binding Messages}" ItemTemplate="{StaticResource MessageTemplate}"/>

   4:     <Sh:AdvancedApplicationBar>

   5:         <Sh:AdvancedApplicationBarIconButton Text="Select" IconUri="/Images/ApplicationBar.Select.png"/>

   6:         <Sh:AdvancedApplicationBarIconButton Text="Remove" IconUri="/Images/ApplicationBar.Delete.png"/>

   7:     </Sh:AdvancedApplicationBar>

   8: </Grid>

The Xaml for the ItemTemplate looks like this

   1: <phone:PhoneApplicationPage.Resources>

   2:     <DataTemplate x:Key="MessageTemplate">

   3:         <StackPanel>

   4:             <TextBlock TextWrapping="Wrap" Text="{Binding Sender}" Style="{StaticResource PhoneTextLargeStyle}"/>

   5:             <TextBlock TextWrapping="Wrap" Text="{Binding Date}" Style="{StaticResource PhoneTextAccentStyle}"/>

   6:             <TextBlock TextWrapping="Wrap" Text="{Binding Content}" Style="{StaticResource PhoneTextNormalStyle}"/>

   7:         </StackPanel>

   8:     </DataTemplate>

   9: </phone:PhoneApplicationPage.Resources>

When we run our application now the output should be similar to this. You can tap on the left side of the screen to select items in the list just like you can in the build in mail application.

messages1 messages2

It is pretty weird to have the Remove button visible when you’re not in selection mode of the MultiSelectList and the same thing goes for the Select button that’s still visible when the MultiSelectList is in selectionMode. To fix this we’ll bind the Visibility property of these ApplicationBarButtons to a boolean property that is also 2 way bound to the IsSelectionEnabled property of the MultiSelectList.

To do this we first need to add a boolean property to the ViewModel called IsInSelectionMode

   1: /// <summary>

   2: /// The <see cref="IsInSelectionMode" /> property's name.

   3: /// </summary>

   4: public const string IsInSelectionModePropertyName = "IsInSelectionMode";

   5:  

   6: private bool _isInSelectionMode = false;

   7:  

   8: /// <summary>

   9: /// Sets and gets the IsInSelectionMode property.

  10: /// Changes to that property's value raise the PropertyChanged event. 

  11: /// </summary>

  12: public bool IsInSelectionMode

  13: {

  14:     get

  15:     {

  16:         return _isInSelectionMode;

  17:     }

  18:  

  19:     set

  20:     {

  21:         if (_isInSelectionMode == value)

  22:         {

  23:             return;

  24:         }

  25:  

  26:         _isInSelectionMode = value;

  27:         RaisePropertyChanged(IsInSelectionModePropertyName);

  28:     }

  29: }

When we have this property we can bind the property to the IsSelectionEnabled property of the MultiSelectList. For some reason this can’t be done in Blend since the DataBinding button is greyed out but coding it in Xaml does work. The binding looks like this in Xaml

   1: <toolkit:MultiselectList ItemsSource="{Binding Messages}" ItemTemplate="{StaticResource MessageTemplate}" IsSelectionEnabled="{Binding IsInSelectionMode, Mode=TwoWay}"/>

The Visibility property of the ApplicationBarButtons isn’t a boolean type so we’ll need a converter to convert the boolean to a Visibility Property. I’m using 2 converters here. 1 is converting the boolean value True to Visibility.Visible and the other converter is also an inverter and is converting True to Visibility.Collapsed.

   1: /// <summary>

   2: /// Converts a boolean to Visibililty

   3: /// </summary>

   4: ///[ValueConversion(typeof(bool), typeof(Visibility))]

   5: public class BooleanToVisibilityConverter : IValueConverter

   6: {

   7:     #region IValueConverter Members

   8:  

   9:     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

  10:     {

  11:         Visibility result = Visibility.Collapsed;

  12:  

  13:         bool val;

  14:  

  15:         if (value != null &&

  16:             bool.TryParse(value.ToString(), out val))

  17:         {

  18:             result = val ? Visibility.Visible : Visibility.Collapsed;

  19:         }

  20:  

  21:         return result;

  22:     }

  23:  

  24:     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

  25:     {

  26:         //You can't convert back

  27:         return null;

  28:     }

  29:  

  30:     #endregion

  31: }

  32:  

  33:  

  34: /// <summary>

  35: /// Converts a boolean to Collapsed Visibililty

  36: /// </summary>

  37: ///[ValueConversion(typeof(bool), typeof(Visibility))]

  38: public class BooleanInverterToVisibilityConverter : IValueConverter

  39: {

  40:     #region IValueConverter Members

  41:  

  42:     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

  43:         {

  44:             Visibility result = Visibility.Collapsed;

  45:  

  46:             bool val;

  47:  

  48:             if (value != null &&

  49:                 bool.TryParse(value.ToString(), out val))

  50:             {

  51:                 result = val ? Visibility.Collapsed : Visibility.Visible;

  52:             }

  53:  

  54:             return result;

  55:         }

  56:  

  57:         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

  58:         {

  59:             //You can't convert back

  60:             return null;

  61:         }

  62:  

  63:         #endregion

  64:     }

Lets Bind the boolean value using the converter to the ApplicationBarIcons. Your Xaml should look like this:

   1: <Sh:AdvancedApplicationBarIconButton Text="Select" IconUri="/Images/ApplicationBar.Select.png" Visibility="{Binding IsInSelectionMode, Converter={StaticResource BooleanInverterToVisibilityConverter}}"/>

   2: <Sh:AdvancedApplicationBarIconButton Text="Remove" IconUri="/Images/ApplicationBar.Delete.png" Visibility="{Binding IsInSelectionMode, Converter={StaticResource BooleanToVisibilityConverter}}"/>

If you run the application again you should be able to see the icons showing up and hiding at the correct times now.

To finish this sample and blogpost up we want the Select button to put the MultiSelectMode in selection mode and the remove button should remove the selected items. Lets start with the Select button. We’ll create a RelayCommand in the viewmodel that puts the MultiSelectList into selectionMode.

   1: private RelayCommand _messageListToSelectModeCommand;

   2:  

   3: /// <summary>

   4: /// Gets the MessageListToSelectModeCommand.

   5: /// </summary>

   6: public RelayCommand MessageListToSelectModeCommand

   7: {

   8:     get

   9:     {

  10:         return _messageListToSelectModeCommand

  11:             ?? (_messageListToSelectModeCommand = new RelayCommand(

  12:                 () =>

  13:                 {

  14:                     IsInSelectionMode = true;

  15:                 }));

  16:     }

  17: }

On the Select ApplicationBarButton we’ll add an EventToCommand behavior that will trigger this RelayCommand. I did this in Blend but the Xaml that is created will look like this:

   1: <Sh:AdvancedApplicationBarIconButton Text="Select" IconUri="/Images/ApplicationBar.Select.png" Visibility="{Binding IsInSelectionMode, Converter={StaticResource BooleanInverterToVisibilityConverter}}">

   2:     <i:Interaction.Triggers>

   3:         <i:EventTrigger EventName="Click">

   4:             <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding MessageListToSelectModeCommand, Mode=OneWay}"/>

   5:         </i:EventTrigger>

   6:     </i:Interaction.Triggers>

   7: </Sh:AdvancedApplicationBarIconButton>

Running the application again will show us that using the select button puts the MultiSelectList in selectionmode so that part is finished. It only took 1 line of code in the relaycommand.

Removing the items is a bit more work since you can’t do a 2 way binding on the SelectedItems of a MultiSelectList because it is not a dependency property. The best way to get this working is setting up a property in the Viewmodel that is going to contain the selected items and update this list every time the selectionchanged event is fired by another EventToCommandBehavior that triggers a RelayCommand called SelectedMessagesChangedCommand. The SelectedMessagesChangedCommand will update the ViewModel property that will later be used to delete the items.

   1: /// <summary>

   2: /// The <see cref="SelectedMessages" /> property's name.

   3: /// </summary>

   4: public const string SelectedMessagesPropertyName = "SelectedMessages";

   5:  

   6: private ObservableCollection<Message> _selectedMessages = null;

   7:  

   8: /// <summary>

   9: /// Sets and gets the SelectedMessages property.

  10: /// Changes to that property's value raise the PropertyChanged event. 

  11: /// </summary>

  12: public ObservableCollection<Message> SelectedMessages

  13: {

  14:     get

  15:     {

  16:         return _selectedMessages;

  17:     }

  18:  

  19:     set

  20:     {

  21:         if (_selectedMessages == value)

  22:         {

  23:             return;

  24:         }

  25:  

  26:         _selectedMessages = value;

  27:         RaisePropertyChanged(SelectedMessagesPropertyName);

  28:     }

  29: }

  30:  

  31: private RelayCommand<IList> _selectedMessagesChangedCommand;

  32:  

  33: /// <summary>

  34: /// Gets the SelectedMessagesChangedCommand.

  35: /// </summary>

  36: public RelayCommand<IList> SelectedMessagesChangedCommand

  37: {

  38:     get

  39:     {

  40:         return _selectedMessagesChangedCommand

  41:             ?? (_selectedMessagesChangedCommand = new RelayCommand<IList>(ExecuteSelectedMessagesChangedCommand));

  42:     }

  43: }

  44:  

  45: private void ExecuteSelectedMessagesChangedCommand(IList parameter)

  46: {

  47:  

  48:     SelectedMessages = new ObservableCollection<Message>(parameter.Cast<Message>());

  49: }

Make sure the EventToCommand behavior is passing the SelectedItems as a command property. This can all be done in Blend but here is the Xaml that should be generated by Blend

   1: <i:Interaction.Triggers>

   2:     <i:EventTrigger EventName="SelectionChanged">

   3:         <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding SelectedMessagesChangedCommand, Mode=OneWay}" CommandParameter="{Binding SelectedItems, ElementName=multiselectList}"/>

   4:     </i:EventTrigger>

   5: </i:Interaction.Triggers>

Now we have the selected messages in our viewmodel we can use our last RelayCommand called DeleteSelectedMessagesCommand to remove the selected messages.

   1: private RelayCommand _deleteSelectedMessagesCommand;

   2:  

   3: /// <summary>

   4: /// Gets the DeleteSelectedMessagesCommand.

   5: /// </summary>

   6: public RelayCommand DeleteSelectedMessagesCommand

   7: {

   8:     get

   9:     {

  10:         return _deleteSelectedMessagesCommand

  11:             ?? (_deleteSelectedMessagesCommand = new RelayCommand(

  12:                 () =>

  13:                 {

  14:                     foreach (Message m in SelectedMessages)

  15:                     {

  16:                         Messages.Remove(m);

  17:                     }

  18:                 }));

  19:     }

  20: }

This needs to be triggered again from an EventToCommand behavior attached to the remove ApplicationBarButton.

   1: <i:Interaction.Triggers>

   2:     <i:EventTrigger EventName="Click">

   3:         <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DeleteSelectedMessagesCommand, Mode=OneWay}"/>

   4:     </i:EventTrigger>

   5: </i:Interaction.Triggers>

We can run our application again and when you press the remove button the selected items should be removed.

This sample proves the SH WP AdvancedApplicationBar is working pretty good and it proves it has features that I didn’t get to work in the BindableApplicationBar for example the Visibility of the ApplicationBarButtons. I think I’m going to use this ApplicationBar more often in my projects.

Hopefully this sample is usefull for you to see what the SH WP ApplicationBar is up to or just to get an impression on how to work with a bit more advanced ApplicationBar scenario’s using MVVM.

Sourcecode for the sample project can be downloaded here

Happy Coding

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Fixing the The Target “GetCopyToOutputDirectoryContentProjectItems” does not exist in the project exception when building your WP7 project

My colleague was installing the Windows Phone 7.1 SDK today and we received the following errors during installation plus a popup box that the bootstrapper had an exception:

Setup could not install the following components:

  • Microsoft XNA game Studio 4.0 Refresh
  • Windows Phone SDK 7.1 Extensions for XNA Game Studio 4.0

sdk error

We retried installing the SDK after a full uninstall and a reboot but this wouldn’t help. This error kept appearing. In the end my idea was that we didn’t need XNA any time soon so we would just let this rest and see if everything was still working. Visual studio 2010 opened up fine, Blend  was working All the templates for a  phone project were there so everything seemed ok.

A few hours later when my colleague opened up an already made project from source control and tried to build the project she informed me that she was getting build errors so I had a look. The exception was

The Target “GetCopyToOutputDirectoryContentProjectItems” does not exist in the project

I never heard of this error before and checked if the project was still building on my machine. Ofcourse it was so the problem was somewhere in her environment. I didn’t immediately make the connection of the XNA installation failure but after some searching I found out that it had to do with some of the MSBUILD .target files that Windows Phone 7.1 projects use that have dependencies on the XNA Game studio.

Getting XNA Game studio installed properly seemed the solution so we tried to get that fixed. The solution is in getting the XNA studio installed without use of the bootstrapper that was crashing and Aaron Stebner made a good post on how to do that here.

Follow all the steps in Aarons guide (the file from step 9 didn’t exist for me so I skipped it) and after this the project would build again.

Everyone happy and back to coding Smile Hopefully this post can help someone else when they run into the same problems as we did because we’ve spend to much precious time to fix this.

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Windows Phone 7 Emulator Skin Switcher 1.0 Beta

In the last few weeks several people started creating their own skins for the Windows Phone 7 Emulator. Switching between different skins was a lot of work by copying files manually to the emulator directory every time you wanted to switch. From now on this is not needed anymore because you can use the Windows Phone 7 Emulator Skin Switcher application I’ve created.

wp7EmulatorSkinSwitcher

You can download the application here: Download

Update! version 1.2 is released and the project is moved to codeplex. you can find the newest version here: http://wp7emuskinswitcher.codeplex.com/

This version is the first beta release with my first set of skins. I added 2 skins from Georg Kalus: the Blue Nokia Lumia 800 and the White/Pink Nokia Lumia 710. I’ve also included the Black Nokia Lumia 800 skin from Pedro Lamas

The complete list of skins included in the application now are:

I’m planning on adding more skins in the near future but didn’t have time for it yet. If you have skins I can use please let me know by comment or on twitter

lumia710whitelumia800pinklumia710black

 

Hopefully this will make your Windows Phone 7 projects even more fun to test!

Happy Coding

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Creating dynamic Windows Phone 7 live tile images client side

One of the best parts of windows phone that makes Windows Phone stand out are the live tiles. Microsoft enables you to do a few out of the box customizations to the live tiles but  when you want to go all out most people think you’ll need to generate the images on a server using ASP.NET and then send them to the application as a notification. This is not always the case, you can also create custom tiles client side running on your phone to show custom messages or imitate the outlook tile for example with a number of how many unread messages you have.

First lets sum up what you can do by default and after that we’ll go into going beyond this and creating even better live tiles by adding multiple images or multiple texts to a live tile using the colors and fonts of your choice.

By default you can set the following properties on a live tile

  • Title (shown in the bottom left)
  • Count (black circle with a number between 1 and 99)
  • BackGroundImage (image to show on your tile)
  • BackTitle (shown in the bottom left on the backside of the tile)
  • BackContent (piece of text shown on the backside of the tile)
  • BackBackGroundImage (Image on the backside of the tile)

Ok this is pretty cool but what if we want to make something like Runkeeper does in their app as shown in the following picture:runkeeper live tile

So how do we generate such image on the client side in Silverlight? The trick behind all this is that you can render a user control as a WriteableBitmap and store this image in the isolated storage of your phone so you can use it as the tile BackGroundImage. The final working codesample is linked at the bottom of this post but I’ll show all code to build this example in this blogpost.

We start of creating a new Silverlight for Windows Phone project. Normally I would use MVVM but for this example I want to make it as simple as possible to focus on the tile part.

We’ll create a new UserControl called “TileControl” which is going to be used as our live tile and a “TileData” class to be used for containing the data we’ll be showing on the  live tile.

   1: public class TileData

   2: {

   3:     public string Text1 { get; set; }

   4:     public string Text2 { get; set; }

   5:     public string ImageSource { get; set; }

   6: }

Create the TileControl, set it to 173 by 173pixels and set the background to use PhoneAccentBrush so the live tile has the color the user has selected. Lets make our designers happy and open up the TileControl in expression blend so our designers (or if you are a devigner you!) can design our live tile with dynamic data.

Add a few text boxes and a image to the control so you have something like this:

   1: <Grid x:Name="LayoutRoot" Width="173" Height="173" Background="{StaticResource PhoneAccentBrush}">

   2:     <TextBlock Height="55" Margin="4,4,3,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="24"/>

   3:     <TextBlock Margin="0,64,-17,-3" TextWrapping="Wrap" FontSize="64" HorizontalAlignment="Right" Width="70" Foreground="White"/>

   4:     <Image Margin="6,55,0,13" Width="100" HorizontalAlignment="Left"/>

   5: </Grid>

In the Data window click the icon “Create sample data from class” and select the TileData class.

create sample data

Edit the sample data so we have some nice data to show. I used the following data:

   1: <CustomLiveTileExample:TileData xmlns:CustomLiveTileExample="clr-namespace:CustomLiveTileExample" 

   2: ImageSource="ApplicationIcon.png" 

   3: Text1="The first Text"

   4: Text2="9"/>

Now drag the fields from the test data window to the text and image control to bind them. After this your XAML should look like this and the design surface should already show a nice live tile with an image and 2 texts. In our code we’ll databind this control to a programmatically filled TileData object.

   1: <Grid x:Name="LayoutRoot" Width="137" Height="137" Background="{StaticResource PhoneAccentBrush}" d:DataContext="{d:DesignData /SampleData/TileDataSampleData.xaml}">

   2:     <TextBlock Height="55" Margin="4,4,3,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="21.333" Text="{Binding Text1}"/>

   3:     <TextBlock Margin="0,50,-10,11" TextWrapping="Wrap" FontSize="48" HorizontalAlignment="Right" Width="70" Foreground="White" Text="{Binding Text2}"/>

   4:     <Image Margin="12,51,65,17" Width="60" Source="{Binding ImageSource}"/>

   5: </Grid>

blend tile

The live tile is ready so lets head back to the main page of our application and add the logic to set the live tile. To trigger the creation of the live tile I’ve added a button on the page and attached a click event. in the button1_Click method I’ll add all code needed to create the live tile.

   1: private void button1_Click(object sender, RoutedEventArgs e)

   2:         {

   3:             TileControl frontTile = new TileControl();

   4:             TileData tileData = new TileData() { ImageSource = "/ApplicationIcon.png", Text1 = "The first text", Text2 = "8" };

   5:             frontTile.DataContext = tileData;

   6:  

   7:             frontTile.Measure(new Size(173, 173));

   8:             frontTile.Arrange(new Rect(0, 0, 173, 173));

   9:             var bmp = new WriteableBitmap(173, 173);

  10:             bmp.Render(frontTile, null);

  11:             bmp.Invalidate();

  12:  

  13:             var isf = IsolatedStorageFile.GetUserStoreForApplication();

  14:             var filename = "/Shared/ShellContent/tile.jpg";

  15:  

  16:             if (!isf.DirectoryExists("/Shared/ShellContent"))

  17:             {

  18:                 isf.CreateDirectory("/Shared/ShellContent");

  19:             }

  20:  

  21:             using (var stream = isf.OpenFile(filename, System.IO.FileMode.OpenOrCreate))

  22:             {

  23:                 bmp.SaveJpeg(stream, 173, 173, 0, 100);

  24:             }

  25:  

  26:             var data = new StandardTileData

  27:             {

  28:                 BackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute)

  29:             };

  30:  

  31:             ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative), data);

  32:         }

First we’ll create a TileControl object called frontTile, then we’ll fill it with our tileData by creating a TileData object and setting the DataContext to tileData. After this we’ll create a WriteableBitmap and set it to 173 by 173 pixels. Well use the Render method to render the usercontrol as a bitmap.

After that we’ll check if the directory in the isolated storage exists and if it doesn’t we’ll create it. After that we’ll open the tile file and use the SaveJpeg method to save the WritableBitmap as a .jpg file (bit of a shame you can’t do png that’s why we’ve set the background color to the PhoneAccentColor). after saving the image the only thing we need to do is Call Create on the ShellTile and we’re done.

Lets run the app, press the button and there it is, our dynamically created livetile.

app1    app2

Download Sample project:

Happy coding!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Tutorial: How to use the Silverlight Toolkit transitions without writing XAML by using the Toolkit behavior extensions

In my last post I announced the new Codeplex project I’ve started called the Windows Phone Silverlight toolkit behavior extensions. In this post I’ll explain how to use the behaviors in this project in Expression Blend to create beautiful page transitions supplied by the Silverlight Toolkit for windows Phone without writing any code or XAML!

how to get started

Download the silverlight toolkit for windows phone and the Windows Phone Silverlight toolkit behavior extensions and install both libraries on your system.

After the installation start Expression Blend and create a new Windows Phone 7 Project.

In the projects window right click “References” and select “Add Reference”add reference

Select the Microsoft.Phone.Controls.Toolkit.dll file and press “Open”add reference 2

Select the PhoneToolkit.Extensions.Behaviors.dll and press “Open”add reference 3

You should now have Microsoft.Phone.Controls.Toolkit.dll and PhoneToolkit.Extensions.Behaviors.dll in your References list.add reference 4

Before the transition behaviors work you will have to change 1 thing in the code because that is just how the Silverlight Toolkit Transitions work. so open App.xaml.cs and locate the following Class: “PhoneApplicationFrame”PhoneApplicationFrame

And Change it to “TransitionFrame”TransitionFrame

Build the project and after building the new behaviors will be added to the Assets window.

behavior

You can drag and drop the new behaviors on your PhoneApplicationPage to enable the tilt effect or enable a page transition. In the Example below I’ve added the EnableTiltEffectBehavior to enable the tilting effect on every clickable usercontrol and I’ve added a TransitionTurnstileInBehavior to show a turnstile animation on entering the page and a TransitionTurnstileOutBehavior to show a turnstile animation on leaving the page.

objectsandtimeline

The transition behaviors have 2 properties where you can set the animation for forward and backward transitions. by default the most common animations are selected.properties

To test if everything is working drag a button on the content grid and add a second page to your application. The button should now have a tilt effect and you should have turnstile animations when navigating between the pages.

If you want to disable the tilt effect for a specific usercontrol you can add the SuppressTiltEffectBehavior on that control and the control will no longer have a tilt effect.

I’ve added a complete sample application showing all the transitions and tilt effect behaviors on the codeplex site of the Windows Phone Toolkit Behavior Extensions

If anything isn’t working contact me on twitter or post a comment

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Started a new Codeplex project: Windows Phone Silverlight Toolkit Behavior Extensions

Of all windows phone development that is done in the world I think almost everyone is using the Windows Phone Silverlight Toolkit you can get from Codeplex. This toolkit adds a lot of new controls and also other cool features as page transitions and a tilt effect on usercontrols so users will get more feedback when clicking in the UI.

This week I started working on a new project with a designer and he asked me how to insert the page transitions on a windows phone application page and I showed him that you’ll have to add a piece of XAML to your code and the page transitions will work. He asked me “Can’t I do this in the designer mode without touching any code?” I didn’t have any right answer for him so that’s why I’ve spend part of my weekend to build some behaviors that can be used to drag this functionality on pages in Expression Blend.

There are behaviors for every type of transition available in the silverlight toolkit. for each transitiontype there is an “in” and “out” behavior for entering and leaving the page. Besides the transition behaviors I’ve also created a behavior to turn the tilteffect on or off

  • EnableTiltEffectBehavior
  • SuppressTiltBehavior
  • TransitionRollInBehavior
  • TransitionRollOutBehavior
  • TransitionRotateInBehavior
  • TransitionRotateOutBehavior
  • TransitionSlideInBehavior
  • TransitionSlideOutBehavior
  • TransitionSwivelInBehavior
  • TransitionSwivelOutBehavior
  • TransitionTurnstileInBehavior
  • TransitionTurnstileOutBehavior

You can download the behaviors here: (important: you also need the silverlight toolkit for this to work)

http://phonetoolkitbehavior.codeplex.com/

On the codeplex site you’ll find a msi release containing the dll that you can include in your project to use these behaviors and I’ve also included a sample application. I’ll also upload the sample application to the marketplace so you can easily test out the performance etc without any trouble.

For a compete tutorial check this blogpost.

This is currently the first release so every feedback is welcome. please let me know by adding a comment here or contact me on twitter

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

New blog template

I got a bit bored with my old blog template so I finally switched to a new one that fitted me better. This new template is better readable and clean and I like the orange color that fits with my employer Avanade. The top picture is inspired by my work and passion for Windows Phone so that’s why I’ve chosen an Image of a Metro line. Winking smile

If you like my template it’s a free template for WordPress called “Twenty Eleven 1.2” and you can just download it from the template gallery in WordPress.

Enjoy!

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Switching Dark/Light theme in Blend for Windows Phone

Today a small tip on how to change the design view of your windows phone 7 application in Expression Blend so you can see it in light or dark theme or check how all the different accent colors look:

This is basic functionality but when I asked around I noticed most people don’t know about this feature so that’s why I wrote this blogpost.

By default in Expression Blend your app will show using the dark theme and the blue accent color. To see how your app looks in white just open the Device window by clicking “Window” –> “Device”

blend device window

When the device window is opened you can switch to the light or dark theme by clicking one of the icons. You can also select the accent color from the pulldown box on the right.

blend select white theme

The result:

blackwhite blend

Happy Coding! Designing!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

PinPin 1.2 update now available in the WP7 Marketplace

First note I want to make: The “Error retrieving ATM locations” bug is fixed in this release!

Here is the story on how it all went down:

Since PinPin’s launch last week I’ve been loaded with feedback from people, most of them were positive but there was also a large group of people who weren’t able to get ATM locations. At first I didn’t have any idea how this was possible since I had tested at many locations in the Netherlands and had asked several colleagues to test the app and it worked for everyone.

Luckily  lots of people were able to find the feedback form in my app and when I received a mail from Marco who had a dev unlocked phone and was receiving the errors I found my chance to find out what was causing the bug. I made a version 1.1 and submitted it to the marketplace (that wasn’t smart because that’s why it took so long to get 1.2 out) but also mailed it to Marco so he could test. 1.1 had the option to save the errors and send a mail with the Error messages and a stacktrace so I could see what was going wrong.

With the error report I received from Marco I could see it was something in the response from the webservice I’m calling to get the ATM data but still couldn’t see what the error was exactly. I again added more logging to the app and asked Marco to test again. This time I could compare my request and response from the server to his and then I found out: The Dutch regional settings were screwing things up. Ofcourse this is a major concern for an app that is only used in the Netherlands Smile

I fixed the bug but had to wait untill version 1.1 had passed certification before I could submit 1.2 Wednesday night 1.1 was approved and I immediately submitted 1.2. Today I received another mail from Microsoft that 1.2 also passed certification. From now on everyone should be able to use PinPin!

If you find any bug in version 1.2 please let me know and I’ll try to fix it asap again.

It can take a while before you’ll get the 1.2 update notification from your phone but you could also manually uninstall your current PinPin installation and reinstall from the marketplace you’ll download version 1.2.

Big thanks to Marco and everyone else who has send feedback concerning this bug. Hopefully you can enjoy PinPin now and if you do don’t try to rate and review the app, it only takes a few seconds!

 

1_thumb 2_thumb 4_thumb2

Oh and if you didn’t have PinPin yet, you can download it here:

Download PinPin for WP7

 

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

Introducing: PinPin for Windows Phone 7

I’m proud to announce my 2nd Windows Phone 7 application available in the marketplace. The new app is called PinPin and is an app to locate an ATM near your location. The app is really simple at this first release, just open the app and the app will retrieve ATM location information near your GPS location.

At this moment PinPin only works if you are located in the Netherlands because there is no worldwide ATM location data available. I’m still looking for this data so if someone knows where to get this please let me know.

PinPin Logo

Below are some screenshots of the application:

1 2 3
4 5 6
7 8

PinPin is available for FREE in the Windows Phone marketplace. download it by clicking the button below:

Download PinPin for WP7

Special Thanks to Christiaan Veeningen for telling me to build this app :)

If like or dislike the app please let me know by rating the app or by submitting a review. You can also contact me through twitter @geertvdc or leave a comment here on my blog.

This is currently the first release of PinPin. I have more plans for the app in the future, here is a roadmap of what to come:

  • Add Dutch language
  • Get Directions (Will have to wait for Mango)
  • Add more Bank logo’s
  • Add more countries
  • Review Comments I get from you!

Hopefully you’ll enjoy this new app!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

WP7 App hub error: The [NeutralResourceLanguage] attribute is missing on the entry assembly. (2003)

Today the Microsoft Windows Phone 7 App Hub got a makeover. My new app was ready for deployment yesterday so logging into the new App hub to deploy my app today was the plan.

After uploading my .xap file the app hub told me the “NeatralResourceLanguage” attribute was missing with the following error:

The [NeutralResourceLanguage] attribute is missing on the entry assembly. (2003)

Not sure what this error means I started looking in Visual Studio. and found the solution for the problem.

  • In Visual Studio 2010 rightclick your project and choose properties
  • At the application tab click the “Assembly information…” button
  • Fill the Neutral Language in the popup
  • Press ok!
  • You’re ready to go!

image

It seems that the new App hub Checks up on more things than the old App hub did. The neutral language is probably something a lot of people will forget so hopefully this helps others who are receiving this error.

The Assembly information can also be changed manually the following way:

  • Open the properties directory in your WP7 project
  • Open the AssemblyInfo.cs file
  • Add the following line at the end of the file:
[assembly: NeutralResourcesLanguage("en-US")]

you’ll also need to add the following line at the top:

using System.Resources;

 

Happy developing and deploying!

Geert van der Cruijsen

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter

My Windows Phone 7 Mango Beta review

The beta of Windows Phone 7.1 codename “Mango” was released last week and in this post I’ll write down my experiences with Mango that I had using it since the launch of the beta.

I’ll try to update this post when I bump into stuff I didn’t write about yet.This post isn’t about describing all new stuff since there are already dozens of other great blog posts about that but I’ll try to write my opinions about how these features are working out or what I am still really missing in Mango.

WP7-Mango

 

Lots of small features that make your life easier:

One of the things I enjoy the most about Mango are the small things that really annoyed me with the 7.0 release of Windows Phone 7, for example the shutdown button that automatically turned of your phone even when the phone is locked. Now in Mango you have to slide down after pressing the power button so no more turning off your phone by accident. Also there is an option to set the pin timeout a bit longer so you don’t have to type in your pin every time you want to use your phone (15 minutes is max when you have policies applied).

One small feature I didn’t read about but seems missing is setting up the mail sync times. On my old phone I used to sync mail automatically with push mail between 7:00 and 23:00 so my phone wouldn’t make so much noise when it’s next to my bed when I’m sleeping. I haven’t found this feature so I think this is a big miss for the Mango release.

 

More Social:

Facebook integration was already great in 7.0 but it just got even better. The threading functionality sounds great but for some reason with US/English and Dutch live accounts something doesn’t seem to work. I really can’t wait for this to start working because seeing this in the movies is so nice!

The “Me” live tile became a lot more useful in Mango because you can get messages in the tile about new updates you have on Facebook. also when clicking on the tile you can use Facebook check in with only a few finger presses.

The use of groups is also added in Mango but I haven’t used this yet. I can keep up with my social updates but maybe this will change when twitter will start working in the retail version of Windows Phone 7.1 (In the Mango Beta twitter integration is not yet available).

Other integration will also be available like LinkedIn but this doesn’t seem to work for me in the Beta either.

 

Dutch Language:

Up until now I only had the English language available which is ok if you only type in English. Since 50% of my communication is in Dutch I really enjoy the added Dutch dictionary added in Mango!

 

Bing!

Before Mango I can’t say I actually used the Bing button other then pressing it by accident. but now 4 new cool features are added that seem to work really good. One of the features that I was really looking forward to is “Bing Vision”. With Bing Vision you can scan barcodes, qr codes, text but also books, cd’s and dvd’s. When you can a book you can automatically open apps like amazon to order this book or get more info about the book. Really great!

 

Besides Bing Vision there is also a button to listen to music like Shazam did in 7.0. Now this feature is build in and is working pretty good. There is also a “Nearby” feature added to Bing to get nearby restaurants, things to see, hotspots etc but there is no Dutch content yet so I only get the nearest locations in Germany….

The last option that is added to Bing is the voice to text search. but I don’t really see the big use of this. when I tested it it made a lot of mistakes and in the same time I could write it.

 

IE9:

What can I say… the old browser in wp7 was a disaster. All other mobile browsers were far superior but now IE9 mobile uses the exact same rendering engine as the desktop version so it is a great improvement. It can render HTML5. has more screen space because the address bar is moved to the bottom (Would hope there would be an option to hide it though to get even more space when reading for example). also when browsing in landscape mode you can now use the address bar which wasn’t possible in 7.0.  You can now also pin websites to your homescreen for fast access to certain websites you use often.

 

7.1 apps:

I have seen a lot of movies and demo’s about cool apps using Mango features but there is no possibility to test those myself except for writing your own apps of course (which I will do!) I do have really high expectations about these apps and all the new features

 

To do:

One major issue a lot of people were missing are tasks but now this is added to your calendar hub and can be synced with exchange.

 

Games hub:

I’ve read a lot about new features in the games hub and the integration with Xbox live but since my Xbox Gamer tag live id is Dutch it’s not possible to use this yet. The list of games is cleaned up though and is looking a lot better than it did in 7.0

 

What is not in but needs to be in?

The one super major thing I really need is Tethering. I can understand not all providers can appreciate this feature but I used it on windows mobile 6.5 and now with the same provider I can’t use it anymore. that’s a bit shame!

the other thing I already mentioned and that is setting up times to sync your stuff and times it shouldn’t but it seems I’m the only one wanting this feature :(

Loads more is in!

Steve Balmer promised us 500 new features so I only touched on this a little but but I hope you enjoyed reading my first opinions about Mango and the Beta. I see a bright feature for WP7

Share on Facebook
Kick It on DotNetKicks.com
Shout it
Post on Twitter