Home > Computers and Internet > WinRT Objects in the Windows Phone 8 Designer

WinRT Objects in the Windows Phone 8 Designer

It is possible to create User Controls for Windows Phone Apps which make use of Windows Phone Runtime types. These WinRT types can’t be loaded inside the designer process. As a consequence, if a User Control has WinRT objects that it tries to load during design time, an error occurs. In both Blend and Visual Studio, the artboard will show an error where the control is with the message “Cannot create an instance of ‘<Control Type>’”.

Cannot create an instance of "ControlWithRtComponent"

To have an improved design experience with this User Control, the author of the control can use DesignerProperties.IsInDesignTool to know if the WinRT types should be instantiated. The code behind the User Control may look something like:

if (!System.ComponentModel.DesignerProperties.IsInDesignTool)
wprc = new WindowsPhoneRuntimeComponent();

With this code inside of the User Control, the WinRT object will be prevented from being loaded when the control is instantiated within Blend. The User Control author can have the control show a default, static image in its place.

Using IsInDesignTool, User Control developers can create designer appearances for their controls, so that app developers can use their controls in either Visual Studio or Blend for Visual Studio when developing new Windows Phone 8 apps.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: