Click here to Skip to main content
Click here to Skip to main content

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

, 28 Oct 2009
Rate this:
Please Sign up or sign in to vote.
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:Design

The WPF and Silverlight Designer for Visual Studio 2010 shares several new design time (dSmile | :) 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.

<span style="color:blue;"><</span><span style="color:#a31515;">Grid </span><span style="color:red;">d</span><span style="color:blue;">:</span><span style="color:red;">DataContext</span><span style="color:blue;">="{</span><span style="color:#a31515;">d</span><span style="color:blue;">:</span><span style="color:#a31515;">DesignInstance </span><span style="color:red;">local</span><span style="color:blue;">:</span><span style="color:red;">Person</span><span style="color:blue;">}">

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

 <span style="color:blue;"><</span><span style="color:#a31515;">Grid </span><span style="color:red;">d</span><span style="color:blue;">:</span><span style="color:red;">DataContext</span><span style="color:blue;">="{</span><span style="color:#a31515;">d</span><span style="color:blue;">:</span><span style="color:#a31515;">DesignInstance </span><span style="color:red;">local</span><span style="color:blue;">:</span><span style="color:red;">Person</span><span style="color:blue;">, </span><span style="color:red;">IsDesignTimeCreatable</span><span style="color:blue;">=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.

Posted in Cider Designer, CodeProject, Data Binding, Expression Blend, Silverlight, Tips, VB.NET, Visual Studio 2010, WPF General

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Karl Shifflett
Architect Gayle Manufacturing Company
United States United States
Karl loves .NET, WPF, WCF, ASP.NET, VB.NET and C#.
 
Awards:
 
  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog
 
Click here to learn about Mole 2010 debugging tool for Visual Studio 2010
 
Click here to read about XAML Power Toys
 

Just a grain of sand on the worlds beaches.

Follow on   Twitter

Comments and Discussions

 
General5'ed PinmemberAmir Mahfoozi28-Nov-11 23:49 
GeneralMy vote of 4 PinmemberHoward Richards26-Apr-11 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 28 Oct 2009
Article Copyright 2009 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid