DevLink – Master Windows 8 Location and Proximity Capabilities

What a great session! Thank you to everyone who attended. I enjoyed preparing the materials for this session and I hope you found it helpful and informative. You may find my Presentation Deck, Code, and a recording of the session below. Feel free to ask me any questions or give me any feedback you’d like in the comments below.

Session Description

The age old punch line “Location, Location, Location” is all too applicable in technology now-a-days. Come learn to leverage Windows 8’s Location API, one of the most important features in the mobile computing world. We’ll cover how to help users locate themselves as well as helping them track their next Ski trip. Proximity is another vital part of many great apps today. Join us to learn to leverage NFC tags and connect to peers through wireless communication. After mastering the Location and Proximity capabilities you’ll be able to create high value Windows Store Apps.

Material Links

Contact InterKnowlogy

If you’re interested in receiving our News Letter please email: curious@interknowlogy.com

If you’re interested in career opportunities please email your resume: findyourcalling@interknowlogy.com

If you’re interested in partnering with us please email: curious@interknowlogy.com

Session 12 of the WinRT Development Class – Hackathon Results and Prize Giveaways (Links to All Class Materials & Recordings)

WinRTWebBannerSmall_JPEG

THAT WAS AWESOME!!! We had some killer apps show up to this and I just wanted to say thanks to everyone who showed attended any of our classes. I am very pleased at how well everyone performed. We had some rough patches, but I’d say this class was a huge success! I’d love to hear what you thought about it! What can we do to improve it?

Special Thanks

First a huge thanks to Kim Schmidt who, despite many struggles during the course of this class, has been an outstanding support. She secured our location and really got this class up and running. So again, a huge thanks to her! Also, vNext_OC has been critical in this event. We want to thank all those who have helped organize the user group and keep it running! Great job! We want to give a special thanks to our hosts Saddleback College. They were tremendous hosts and helped us a ton! And a huge thanks to Microsoft for sponsoring dinner each night. It was delicious! Of course we wouldn’t be anywhere with out our prizes so another giant thanks to Microsoft and Nokia DVLUP who sponsored all of the cool prizes and giveaways! Kevin and I have feel honored and privileged to have worked with such amazing sponsors, leaders, and attendees! Thank you everyone for your participation!

WP_20130520_008

Overview Of Sessions

Blog Post Links (posts contain links to recorded sessions 2-11):

Development Environment for Windows 8

Session 1 & 2 of the WinRT Development Class – Introduction, XAML, and WinRT’s Control Framework

Session 3 of the WinRT Development Class – App Lifecycle and Navigation

Session 4 of the WinRT Development Class – Async/Await, WinRT API, and Security

Session 5 of the WinRT Development Class – Search and Settings

Session 6 of the WinRT Development Class – Share Contract

WinRT Development Class – Spring Break Update

Session 7 of the WinRT Development Class – Live Tiles and Background Tasks

Session 8 of the WinRT Development Class – Orientation And Near Field Communication

Session 9 of the WinRT Development Class – Intro to Model-View-ViewModel (MVVM)

Session 10 of the WinRT Development Class – InterKnowlogy’s WinRT MVVM Framework Part I/II

Session 11 of the WinRT Development Class – InterKnowlogy’s WinRT MVVM Framework Part II/II

MeetUp Links:

1. Introductory Lecture (Nov 27th by Danny & Kevin)
2. Introduction to XAML and WinRT’s powerful Control Framework; (Dec 4th by Danny & Kevin Click here for the video recording)
3. Page-Navigation Model and Application Lifecycle (Jan 8th by Danny Click here for the video recording)
4. Fundamentals (Async/Await, WinRT API, Security) (Jan 15th by Kevin Click here for the video recording)
5. Settings and Search Contract (Jan 28th by Danny Click here for the video recording)
6. Share Contract (Feb 4th by Kevin Click here for the video recording)
7. Live Tiles and Background Tasks (March 18th by Kevin Click here for the video recording)
8. Orientation Handling and Proximity using Near Field Communication (NFC) (March 25th by Danny Click here for the video recording)
9. Introduction to ModelViewViewModel (MVVM) (April 8th by Danny Click here for the video recording)
10. InterKnowlogy’s WinRT MVVM Framework Session Part I/II(April 22nd by Kevin Click here for the video recording)
11. InterKnowlogy’s WinRT MVVM Framework Session Part II/II(May 6th by Danny Click here for the video recording)
12. Presentation of Hackathon Results + Certificate/Prize Giveaway(May 20th by Danny and Kevin)

Session 11 of the WinRT Development Class – InterKnowlogy’s WinRT MVVM Framework Part II/II

WinRTWebBannerSmall_JPEG_thumb[1]

That’s a wrap! All code sessions are now complete! Awesome! Now to see the Hackathon results!

Session Resources

Overview Of Sessions

The links below lead you to Meetup Events where you can RSVP. We look forward to seeing you at our next session!

1. Introductory Lecture (Nov 27th by Danny & Kevin)
2. Introduction to XAML and WinRT’s powerful Control Framework; (Dec 4th by Danny & Kevin Click here for the video recording)
3. Page-Navigation Model and Application Lifecycle (Jan 8th by Danny Click here for the video recording)
4. Fundamentals (Async/Await, WinRT API, Security) (Jan 15th by Kevin Click here for the video recording)
5. Settings and Search Contract (Jan 28th by Danny Click here for the video recording)
6. Share Contract (Feb 4th by Kevin Click here for the video recording)
7. Live Tiles and Background Tasks (March 18th by Kevin Click here for the video recording)
8. Orientation Handling and Proximity using Near Field Communication (NFC) (March 25th by Danny Click here for the video recording)
9. Introduction to ModelViewViewModel (MVVM) (April 8th by Danny Click here for the video recording)
10. InterKnowlogy’s WinRT MVVM Framework Session Part I/II(April 22nd by Kevin Click here for the video recording)
11. InterKnowlogy’s WinRT MVVM Framework Session Part II/II(May 6th by Danny Click here for the video recording)
12. Presentation of Hackathon Results + Certificate/Prize Giveaway(May 20th by Danny and Kevin)

Session 9 of the WinRT Development Class – Intro to Model-View-ViewModel (MVVM)

WinRTWebBanner_JPEG

This class was really made possible by all those who attended. And a special thanks to Tom Hannum for lending me your power cord. We all learned a lot at this session. I hope everyone will go review the presentation video and get familiar with MVVM. If you have any questions leave a comment below! Happy Coding!

Session Resources

Overview of Sessions

The links below lead you to Meetup Events where you can RSVP. We look forward to seeing you at our next session!

1. Introductory Lecture (Nov 27th by Danny & Kevin)
2. Introduction to XAML and WinRT’s powerful Control Framework; (Dec 4th by Danny & Kevin Click here for the video recording)
3. Page-Navigation Model and Application Lifecycle (Jan 8th by Danny Click here for the video recording)
4. Fundamentals (Async/Await, WinRT API, Security) (Jan 15th by Kevin Click here for the video recording)
5. Settings and Search Contract (Jan 28th by Danny Click here for the video recording)
6. Share Contract (Feb 4th by Kevin Click here for the video recording)
7. Live Tiles and Background Tasks (March 18th by Kevin Click here for the video recording)
8. Orientation Handling and Proximity using Near Field Communication (NFC) (March 25th by Danny Click here for the video recording)
9. Introduction to ModelViewViewModel (MVVM) (April 8th by Danny Click here for the video recording)
10. InterKnowlogy’s WinRT MVVM Framework Session Part I/II(April 22nd by Kevin)
11. InterKnowlogy’s WinRT MVVM Framework Session Part II/II(May 6th by Danny)
12. Presentation of Hackathon Results + Certificate/Prize Giveaway(May 20th by Danny and Kevin)

Accessing Dependency Property (DP) Changed in WinRT

With the release of Windows 8 and WinRT, I began the process, during RECESS, of porting an existing app we’d created for the Microsoft Surface (the team that is now called “Pixel Sense”) to be a Windows Store application. The application followed more of an MVC (Model View Controller) approach, rather than MVVM (Model View ViewModel), so there we a number of controls that subscribed to the DataContext and Visibility changed events in their code behind, which don’t exist in WinRT.

WinRT (Windows Store) applications seem to have many of the same limitations that Silverlight had, compared to WPF, and rather than rewrite the parts of the application to try and avoid needing to know when these DPs changed, I came up with a simple framework to register for a callback when a specified DP changed.

First Solution

The way to get around this issue was actually really straight forward. In each control, I created and registered a DP for each DP I wanted a change notification from (ie. DataContextEx, VisibilityEx, etc…).

public static readonly DependencyProperty DataContextExProperty =
		  DependencyProperty.Register( "DataContextEx", typeof( object ), typeof(DemoControl ),
			new PropertyMetadata( null, OnDataContextExChanged ) );

public object DataContextEx
{
	get { return (object)GetValue( DataContextExProperty ); }
	set { SetValue( DataContextExProperty, value ); }
}

private static void OnDataContextExChanged( DependencyObject d, DependencyPropertyChangedEventArgs e )
{
	( (DemoControl)d ).OnDataContextExChanged( e );
}

private void OnDataContextExChanged( DependencyPropertyChangedEventArgs e )
{
	//Handle the change
}

Then, in the control’s constructor, I bound the created DP(s) to the related DP I wanted to know had changed. With this binding, whenever the source DP (ie. DataContext, Visibility, etc…) changed it would cause the “extension” DP to change and that would call the changed handler I registered when creating the DP.

var binding = new Binding
			{
				Path = new PropertyPath("DataContext"),
				RelativeSource = new RelativeSource
								{
									 Mode = RelativeSourceMode.Self
								}
			};
SetBinding(DataContextExProperty, binding);

With this I had all that I needed. However, I hated the idea of having to rewrite this code on every control that I needed the notification on. So I decided to create a framework to allow me to register for a changed callback on any FrameworkElement.

Framework

I decided to go the route of creating a FrameworkElement extension method called RegisterDependencyPropertyChanged that takes a lambda expression for the property to bind to and a callback for when that property changes.

this.RegisterDependencyPropertyChanged( () => DataContext, DataContextChangedHandler );

The extension then calls RegisterDependencyPropertyBinding on FrameworkElementAttachedProperties. FrameworkElementAttachedProperties is an internal class that holds the functionality to create and register an Attached DP for each type of DP (ie. DataContext, IsHitTestVisible, Visibility, etc..) the user desires a callback for and bind that Attached DP to the DP (using the same process defined under First Solution. Then whenever that value changes it attempts to find a callback registered for it, and if one is found, calls the registered callback with the DependencyPropertyChangedEventArgs provided.

Attached DPs are only able to be bound to one property of an object at a time (but can be bound to the same property of multiple objects). This is why an Attached DP is created and registered for each DP of a control as there may be a case where a change callback is registered for more than one property of that control. Therefore whenever FrameworkElementAttachedProperties.RegisterDependencyPropertyBinding is called it calls GetNextUnusedAttachedPropertyForFrameworkElement. This either grabs an existing Attached DP registered for that property, or it will create and register a new one and return it.

private static DependencyProperty GetNextUnusedAttachedPropertyForFrameworkElement( string propertyName )
{
	if ( !_staticExtensionDPs.ContainsKey( propertyName ) )
	{
		var unusedDependencyProperty = DependencyProperty.RegisterAttached( _extensionDPsNamePrefix + "_" + propertyName,
													   typeof( object ),
													   typeof( FrameworkElementAttachedProperties ),
													   new PropertyMetadata( null, DependencyPropertyExPropertyChanged ) );
		_staticExtensionDPs.Add( propertyName, unusedDependencyProperty );
	}
	
	return _staticExtensionDPs[propertyName];
}

The registered callbacks are stored in the DependencyPropertyCallbacks Attached DP on FrameworkElementAttachedProperties. By storing the callbacks in the Attached DP, when the control that has registered is unloaded, it can be collected by the Garbage Collector and there aren’t memory leaks.

Conclusion

I tend to prefer the MVVM approach, but there are cases when constraints dictate that a different approach is used. This is a nice little addition for when that occurs. Here is a demo solution containing the framework (FrameworkElementExtension.cs) and an example of how to use it.

Installing Win8 Consumer Preview on the Samsung 700T

Since September, I’ve been using the Developer Preview version of Windows 8 that came with the Samsung 700T tablets that we got at //BUILD/, but today Microsoft released the next update to Win8 – the Consumer Preview.  Obviously, it came out today, so it’s time to update the device!

I couldn’t find any documentation showing how to upgrade / install the new OS, and heard that upgrades are not supported in these pre-release bits, so I was ready to wipe the device and install clean.  Through trial and error, here’s how I installed the Consumer Preview version.

The plan was to boot from a USB thumb drive that has the contents of the installation media on it.   You’ll see below that it wasn’t the normal “boot from ISO” experience that I’m used to on a desktop PC.

Create Bootable USB Thumb Drive

Most importantly, you can only use a thumb drive that is 4 GB in size. The hardware does not recognize larger drives than that.

Use the Windows 7 USB/DVD download tool to create a bootable USB drive from the .ISO file.  I think this is similar to expanding the contents of the .ISO onto the USB drive, but then it also makes it bootable as well.  As you’ll see below, I didn’t end up actually BOOTING from the USB drive, so making it bootable is probably an extraneous step.

Insert the USB thumb drive into the device.

Enter “BIOS” at Startup

This was new to me.  When the device is powering up, hold down the START button until you see the “Preparing Options” message at the bottom.  IMG_20120229_141943This brings you to what seems to be the equivalent of BIOS options, but with a Win8 layer on top of it running the show (touch works in this UI).

(Excuse the nasty camera pics here – couldn’t take actual screenshots when down in the low level BIOS options.)

Choose TROUBLESHOOT.

Choose ADVANCED OPTIONS.

Choose COMMAND PROMPT.

At this point you will be prompted for account credentials.  This is another area new to me – requiring account credentials on the device at this “low level” before you can go hacking on the system.

IMG_20120229_142049

Command Prompt – Run SETUP

Now you will be at a familiar command prompt, at the X drive (not sure what drive this is).

CD to the D drive, which on my device is the USB thumb drive.  Notice the directory listing is the Win8 Consumer Preview installation software from the ISO.

IMG_20120229_142149

Now from the root of the D drive, run SETUP.  Up comes the first step of the installation…

IMG_20120229_142206

From here, after a couple intro steps, I chose “Custom” installation since I want to wipe my device, not an upgrade, and had to choose a partition…

Crazy List of Partitions

It turns out there are 5 partitions on my device.  The main one where Win8 Developer Preview is installed is Partition 5.  IMG_20120229_142506I deleted that one (drive options, advanced) and installed to that partition.

Finally … we’re on to the “normal” installation of Windows 8…

IMG_20120229_143027

Windows 8 Consumer Preview

Ahh, the start screen…

Tablet Win8 CP - Start Screen

Using Kinect in a Windows 8 / Metro App

We have been working with the Kinect for a while now, writing various apps that let you manipulate the UI of a Windows app while standing a few feet away from the computer – the “10 foot interface” as they call it.  Very cool stuff.  These apps make use of the Microsoft Kinect for Windows SDK to capture the data coming from the Kinect and translate it into types we can use in our apps:  depth data, RGB image data, and skeleton points.  Almost all of these apps are written in C# / WPF and run on Windows 7.

Last month a few of us went to the Microsoft //BUILD/ conference, and came back to start writing apps for the new Windows 8 Metro world.  Then naturally, we wanted to combine the two and have an app that uses Kinect in Windows 8 Metro.  At InterKnowlogy we have a “Kiosk Framework” that fetches content (images, audio, video) from a backend (SQL Server, SharePoint) and has a client for various form factors (Win7, Surface, Win Phone 7) that displays the content in an easy-to-navigate UI.  Let’s use the Kinect to hover a hand around the UI and push navigation buttons!  Here’s where the story begins.

One of the First Metro Apps to Use Kinect

Applications that are written to run in Windows 8 Metro are built against the new Windows Runtime (WinRT) API, which is the replacement for the old Win32 API that we’ve used since Windows 3.0.  The problem when it comes to existing code is that assemblies written in .NET are not runtime compatible with WinRT (which is native code).  There is a lot of equivalent functionality in WinRT, but you have to port existing source code over, make changes where necessary, and compile specifically against WinRT.  Since the Kinect SDK is a set of .NET assemblies, you can’t just reference it in your WinRT / Metro app and start partying with the Kinect API.  So we had to come up with some other way…

You CAN write a .NET 4.5 application in Windows 8, using Visual Studio 11 and it will run on the “desktop” side of the fence (alternate environment from the Metro UI, used for running legacy apps).  So we decided to take advantage of this and write a “Service” UI that will run in the classic desktop environment, connect to the Kinect and receive all the data from it, and then furnish that data out to a client running in the Metro side.  The next issue was – how to get the data over to our Kiosk app running in Metro?  Enter web sockets.  There is a native implementation of web sockets in the WinRT framework and we can use that to communicate on a socket channel over to the .NET 4.5 desktop which can reply to the client (Metro) socket with the Kinect data.

Some Bumps in the Road

Writing the socket implementation was not conceptually difficult.  We just want the client to poll at a given frame rate, asking for data, and the service will return simple Kinect skeleton right-hand position data.  We want to open the socket, push a “request” message across to the service, and the service will write binary data (a few doubles) back to the caller.  When pushing bytes across a raw socket, obviously the way you write and read the data on each side must match.  The first problem we ran into was that the BinaryWriter in the .NET 4.5 framework was writing data differently than the DataReader in WinRT was receiving the data.

As with any pre-release software from MIS, there is hardly any documentation on any of these APIs.  Through a ton of trial and error, I found that I had to set the Unicode and Byte Order settings on each side to something that would match. Note the highlighted lines in the following code snippets.

    // Send data from the service side

    using ( MemoryStream ms = new MemoryStream() )
    {
        using ( BinaryWriter sw = new BinaryWriter( ms, new UnicodeEncoding() ) )
        {
            lock ( _avatarPositionLock )
            {
                sw.Write( _lastRightHandPosition.TrackingState );
                sw.Write( _lastRightHandPosition.X );
                sw.Write( _lastRightHandPosition.Y );
            }

        }

        Send( ms.GetBuffer() );
    }
    // Receive data in the client 

    DataReader rdr = e.GetDataReader();

    // bytes based response.  3 ints in a row
    rdr.UnicodeEncoding = UnicodeEncoding.Utf16LE;
    rdr.ByteOrder = ByteOrder.LittleEndian;
    byte[] bytes = new byte[rdr.UnconsumedBufferLength];

    var data = new JointPositionData();
    var state = rdr.ReadInt16();
    Enum.TryParse<JointTrackingState>( state.ToString(), out data.TrackingState );
    data.X = rdr.ReadDouble();
    data.Y = rdr.ReadDouble();

    UpdatePositionData( data );

Once I got the socket channel communicating simple data successfully, we were off and running.  We built a control called HoverButton that just checks whether the Kinect position data is within its bounds, and if so, starts an animation to show the user they’re over the button.  If they hover long enough, we fire the Command on the button.

The next problem was connectivity from the client to “localhost” which is where the service is running (just over in the desktop environment).  Localhost is a valid address, but I would keep getting refused connections.  Finally re-read the setup instructions for the “Dot Hunter” Win8 SDK sample which tells about a special permission that’s required for a Win8 app to connect to localhost.

PackageFamilyName

Open a command prompt as administrator and enter the following command (substitute your package name for the last param):

    CheckNetIsolation LoopbackExempt -a -n=interknowlogy.kiosk.win8_r825ekt7h4z5c

There is no indication that it worked – I assume silence is golden here.  (I still can’t find a way to list all the packages that have been given this right, in case you ever wanted to revoke it.)

CheckNetIsolation

Finally, a couple other minor gotchas:  the service UI has to be running as administrator (to open a socket on the machine), and the Windows Firewall must be turned OFF.  Now we have connectivity!

What’s Next?

Beyond those two problems, the rest was pretty straight forward.  We’re now fiddling with various performance settings to achieve the best experience possible.  The skeleton data is available from the Kinect on the desktop side at only about 10 frames per second. We think this lower rate is mostly due to the slower hardware in the Samsung Developer Preview device we got from BUILD.  Given that speed, the Metro client is currently asking for Kinect data from the service at 15 frames per second.  We are also working on better smoothing algorithms to prevent a choppy experience when moving the hand cursor around the Metro UI.

Crazy WinRT XAML Bug in Windows 8 Developer Preview

I’ve been playing with the developer preview release of Windows 8 that we got from //BUILD/.  Everyday, we find more and more “issues” that are either just straight up bugs, things that are not implemented yet, or maybe even issues that won’t be resolved because WinRT is “just different”.  This one was especially “fun” to track down – and when we did, we couldn’t believe the issue.

Start with a simple WinRT application in Visual Studio 11.  Add a class library project that will hold a couple UserControls that we’ll use in the main application.  Pretty standard stuff.

Create 2 UserControls in the library, the first one will use the other.  UserControl1 can just have some container (Grid) then use UserControl2 (which just has an ellipse).  In the main application, add a reference to the ClassLibrary and use UserControl1 in the MainPage.  Your solution should look something like this:

Solution

  <!-- MainPage.xaml -->
  ...
  xmlns:controls="using:ClassLibrary1.Controls"
  ...

<Grid x:Name="LayoutRoot"
    Background="#FF0C0C0C">
  
  <controls:UserControl1 />
  
</Grid>
  <!-- UserControl1.xaml -->
  ...
  xmlns:controls="using:ClassLibrary1.Controls"
  ...

  <Grid x:Name="LayoutRoot"
      Background="#FF0C0C0C">
    
    <controls:UserControl2 />

  </Grid>
  <!-- UserControl2.xaml -->

  <Ellipse Height="40" Width="40" Fill="Red" />

Now here’s the key step.  Add a new class to the ClassLibrary, say Class1, and have that class IMPLEMENT INotifyPropertyChanged (be sure to choose the right using statement – the one from UI.Xaml.Data).

    public class Class1 : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

That’s it.  Run it.

You will get a runtime exception:

Exception

Crazy, huh?  The Microsoft guys have confirmed this to be a known bug.  I just can’t believe what that bug would be?  How is a simple UNREFERENCED class that implements INPC getting in the way of a couple UserControls?

Ahh … the joys of coding against pre-release software…

Windows 8 WinRT Development 101

Let there be no mistake made that it’s pretty exciting that Microsoft is starting to release early bits for some of its products for us to test out. Windows 7, Visual Studio 2008 (Orcas), VS2010, VS11, Win8, etc. are just a few that come to my mind. These early releases are full of bugs and are definitely not production quality, neither should they be. So I’m just going to go ahead and preface everything I’m going to write with, “The Win8 WinRT framework is pre-beta and therefore should not be expected to work exactly as prescribed.” With that said there are a few key features that don’t work as expected and I’ll be touching on some of those.

Motivation
I’m currently on a project with two other developers here at InterKnowlogy, Dan Hanan and Carmine Sampogna. We are at the tail end of porting what we call our Kiosk Framework to Windows 8 on the WinRT framework. The project has been a ton of fun and we’ve learned a lot. The project has not been as straight forward as we would have hoped. WinRT XAML is similar in capabilities to Silverlight 3 and 4. Sometimes you still feel like you’re in SL2, but again it is pre-beta software.
Environment
Carmine and I are running Win8 from bootable VHDs that we made following the steps in a post by another coworker Travis Schilling. Dan received one of the coveted Win8 Tablets from BUILD. And we’ve installed the full developer preview of VS11.

WinRT Gotcha’s
Only one merged resource dictionary supported: We like to organize our XAML Resources into Resource Dictionaries to help with readability. It also allows multiple controls to share a single resource and multiple developers to work on different resources at the same time without the need for merging XAML files. So naturally we went down this path only to find that this is not supported yet in WinRT. We got the following error:

We found some help from someone who had already encountered the problem: http://metrotrenches.wordpress.com/2011/10/07/tailored/.

DependencyProperties are not typed: DependencyProperties are very important when designing UserControls that you intend to be used in different contexts with different DataContexts. In the current version of WinRT DPs are not typed, which is a big bummer. This work around was found at: http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/4fed80a8-1343-41ca-8c27-b20a00689f65.

ElementName bindings only sorta-kinda work: ElementName bindings help simplify and centralize values. One element contains the values and a bunch of others can grab those values. They are very important when it comes to attempting to implement a MutltiBinding workaround. However, we have found that in many cases ElementName bindings don’t work while in other cases it does. Not sure why.

Can’t retrieve non-template resources such as double, GridLength, Thickness, etc.: I discovered this because ElementName bindings were failing in a very specific case.


var myGridLegnth = App.Current.Resources["MyGridLength"];  //fails
var myDataTemplate = App.Current.Resources["MyDataTemplate"] as DataTemplate; //works

Works just fine if you are accessing a DataTemplate, ControlTemplate, or Style. However it seems to fail for structs, value types, and complex types.

DataTemplates cannot contain ContentControls that use ContentTemplateSelectors in some cases: I was trying to refactor a DataTemplate into App.xaml (because we can’t have multiple ResourceDictionarys) and I would continually get an Engine Execution Exception.

No Implicit DataTemplates: However there are implicit Styles.

Other Thoughts
One of the most annoying parts about development is that every run of our application is cut short by a FatalExecutionException which claims may be a bug in the CLR, or an ExecutionEngineException with no details. We can’t seem to get around these. Also, any exceptions thrown by bad XAML at runtime have zero details about what is wrong. Sometimes we get exceptions that have nothing to do with XAML or our UserControl but the exception is still thrown by a UserControl. Very Strange.
My coworker Dan has a post with more gotcha’s and his take on Win8. Overall, Win8 is cool, but the preview is severely lacking. We’re hoping it doesn’t take another 6+ months to get new bits!

Icons for Windows 8 Metro Application Buttons

To make it easier to use standard button icons, a new Segoe UI Symbol font has been added to Windows 8 that currently includes 25 icons. The available icons are listed below with their hex and base 10 values. The icons can be used from XAML like: <TextBlock Text=”&#57615;” FontFamily=”Segoe UI Symbol”/>

IconFontChart