Showing posts with label WP7. Show all posts
Showing posts with label WP7. Show all posts

Thursday, February 3, 2011

Tombstoning MVVMLight ViewModels with an ApplicationBar using SilverlightSerializer

I've first implemented Tombstoning MVVMLight ViewModels using the default DataContractSerializer. I save the ViewModel when closing the application to persistent storage by using the IsolatedStorageSettings.ApplicationSettings. When deactivating the application I saved the ViewModels to transient storage using PhoneApplicationService.Current.State. This method has some limitations regarding maximum storage size. Second problem was that the MVVMLight ViewModelBase class constructor was not public and therefor could not be serialized. I fixed this by just downloading the sources and use the new assemblies.
I wasn't really satisfied. When I was at the DotNed meeting at Qurius there was a discussion about saving states and what serializers would be a good option. The SilverLightSerializer was the one I remembered, so back at home I did some digging and found that LocalJoost blogged about it.
I implemented the SilverLightSerializer and just needed to replace the saving and loading state parts. Than I tested the application and found out the application bar was gone after a deactivate / activate cycle.
Before deactivating:
Then do a 'Start' and 'Back', it will activate in a state like this:
I also had this problem before using the DataContractSerializer. That was fixed by decorating the public ApplicationBar properties with [IgnoreDataMember] attribute. The SilverLightSerializer skips properties from being serialized which are decorated with the [DoNotSerialize] attribute. So I replaced the [IgnoreDataMember] with [DoNotSerialize] and the ApplicationBar was back again.
Hopes this saved you some hours of searching and testing.

Sunday, January 16, 2011

Silverlight Toolbox GestureListener not working great when developing using Remote Desktop


The Silverlight for Windows Phone Toolkit is working fine in normal environments, great toolkit. However when I started developing WP7 apps in the living room and used a Remote Desktop connection to the development machine I encountered very bad gesture responses in the Windows 7 Emulator. The Flick gesture on the emulator screen didn't do anything (well about 1 out of 100). Doing it again 1 minute later on de development machine without RDS and it worked all the time. Other gestures worked fine. Maybe it's something with the mouse events?

The XAML code I used:

<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick">
</toolkit:GestureListener>
</toolkit:GestureService.GestureListener>

Code behind:

   1: if (ViewModel.ViewModelLocator.MainStatic.TossCmd.CanExecute(e))
   2: {
   3:     ViewModel.ViewModelLocator.MainStatic.TossCmd.Execute(e);
   4: }

Setting a breakpoint on line 1 never kicked in.