Wednesday, September 14, 2011

Random tips for Windows 8 / WinRT

Check if you're in the designer:
bool Windows.ApplicationModel.DesignMode.DesignModeEnabled

Reflection:
Cast Type object to IReflectableType (maybe do an "as" and check for null?), and call IReflectableType.GetTypeInfo(). TypeInfo has access to members and properties and such.

XAML namespace declaration:
The old way looked like this:
xmlns:local="clr-namespace:SharkDice"
Now, use "using:":
xmlns:local="using:SharkDice"

Dispatcher (to invoke on UI thread):
Window.Current.CoreWindow.Dispatcher

ViewModels / MVVM / INotifyPropertyChanged:
None of the sample code uses MVVM, which is a little scary. Apparently INotifyPropertyChanged exists in System.ComponentModel and Windows.UI.Xaml.Data, but the only sample that uses either uses Windows.UI.Xaml.Data. Sometimes it gets a little weird and won't build though. Make sure everything builds and works correctly before you implement.

Event Accessors:
I couldn't get event accessors (add / remove) to work at all. Got some very strange build issues.

VS2011 XAML Design Surface Failure:

System.Runtime.Remoting.RemotingException

[3928] Designer process terminated unexpectedly!

Sometimes I get this error when I've written bad XAML, but twice I've put Visual Studio in a state where the designer is just permanently broken. I can open the same project on another Win8 machine and it works, but no amount of restarts, Cleans, etc. will bring back the design surface. For this reason I recommend doing dev work in a virtual machine or something you can easily and quickly recover or restore without losing your work.
NOTE: Doing a "refresh" (Metro Control Panel -> General -> Refresh your PC) fixed Visual Studio for me, but it was painful as I lost all my installed apps and some settings).
 
Things of question / note:
  • Why can Blend Preview only open HTML / JavaScript projects? Currently no easy way to edit templates and storyboards.
  • How to embed custom fonts? Silverlight and WPF methods don't work.
  • Replacement for Silverlight Projection? (Sad this is gone as I always hated that it wasn't in WPF)
  • Where is IsolatedStorage equivalent?
  • Where is non-generic IDictionary or equivalent?
  • Is there a replacement for Application.ApplicationLifetimeObjects? (not hard to replicate ourselves)

1 comment:

  1. Windows.Storage is the replacement for IsolatedStorage.

    Why do you need non-generic dictionaries? :)

    ReplyDelete