d:DesignInstance, d:DesignData in Visual Studio 2010 Beta2

The WPF and Silverlight Designer for Visual Studio 2010 shares several new design time (d:) properties and design time MarkupExtensions with Expression Blend 3 that provide necessary information for the WPF and Silverlight Designer to deliver a great editing experience.

I have explained the d:DesignData MarkupExtension in detail in this blog post:  Visual Studio 2010 Beta2 Sample Data Project Templates.

In this post I’ll cover the d:DataContext property and the d:DesignInstance MarkupExtension.

d:DataContext

d:DataContext gives developers the ability to set a design time d:DataContext that is separate and independent of the run-time DataContext property.

This feature solves the problem of developers wanting to set their DataContext programmatically but also wanting design time data.

All d: properties are ignored during compilation and are not part of any run-time assemblies.

d:DesignInstance

Purpose:  Provides a design time shape to the d:DataContext its applied to.

Example:  In the below snippet the Person class is the shape provided by d:DesignInstance to the Grid’s d:DataContext.

<Grid d:DataContext="{d:DesignInstance local:Person}">

Note: In the above example, the Person class is actually a faux type (fake or substitute type).  This faux type enables types that are not creatable to be created and their properties exposed as a shape.  See the below section on creating creatable types.

Usage:  So, now that the d:DataContext has shape, what can I do with it?

The shape is used by the new Binding Builder to expose the properties of the type in d:DataContext.  You can see in the below image, the four properties exposed by the Person class.

BindingBuilder

The Binding Builder is opened by clicking or right clicking on the Property Marker in the Properties Window.  The Property Marker is the icon to the right of the property name.  The Binding Builder is a GUI for editing bindings in WPF and Silverlight.  This is a super feature

The Cider Team has a great explanation of the new features on WindowsClient.net that you can read here: Setting Up Visual Studio for WPF and Silverlight Development.  There is an article and video.

You can read additional Cider Team Online material here:  WPF and Silverlight Designer for Visual Studio 2010.  We are in the process of adding many more articles.  While the material is initially geared for developers coming from other platforms to WPF or Silverlight, it has a lot of great information even for the seasoned XAML Head.  Yea, I said it.  I’m a XAML Head too and proud of it.  (LOL)

Without d:DesignInstance, d:DesignData or d:Source applied to a CollectionViewSource the Binding Builder would have no way to determine shape and provide a list of properties.

Note:  If d:DataContext is not set, but DataContext is set and has a created type assigned to it, this will also supply shape that the Binding Builder can use for listing properties.

Creating Creatable Types

 <Grid d:DataContext="{d:DesignInstance local:Person, IsDesignTimeCreatable=True}">

d:DesignInstance provides a technique for creating a non-faux type.  Setting the property IsDesignTimeCreatable to True on the d:DesignInstance MarkupExtension enables this.

Links

MSDN d:DesignInstance Walkthrough

Video showing d:DesignData and d:DesignInstance can be viewed from this blog post:  Visual Studio 2010 Beta2 Sample Data Project Templates.

The above post also has source code for sample data templates.  There four of the templates are tutorial walkthroughs on this topic and sample data.

The two .xaml files in the DesignInstance Samples folder are the walkthroughs.  You can create this project in VB.NET or C# by using one of the below templates when creating your project.

  • VB WPF Application DesignData Sample – VB.NET Sample WPF Application that demonstrates consuming sample data.
  • CS WPF Application DesignData Sample – C# Sample WPF Application that demonstrates consuming sample data.

DesignInstanceExamples

Close

Hope you find d:DesignInstance and d:DesignData Sample Data in Visual Studio 2010 Beta2 a productive feature for your application development.

Have a great day,

Just a grain of sand on the worlds beaches.

4 Responses to d:DesignInstance, d:DesignData in Visual Studio 2010 Beta2

  1. [...] Options for Visual Studio 2010 Beta2 WPF and Silverlight Projects and d:DesignInstance, d:DesignData in Visual Studio 2010 Beta2 (Karl [...]

  2. [...] post: d:DesignInstance, d:DesignData in Visual Studio 2010 Beta2 « Karl … By admin | category: silverlight studio | tags: cider-team, designer, initially-geared, [...]

  3. [...] best two articles are by Unni and Karl but there are a few things they don’t [...]

  4. [...] gleaned most of what I have learned about this topic from Unni, Karl, and Jack. I recommend checking out their posts for additional [...]

Follow

Get every new post delivered to your Inbox.

Join 245 other followers