<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ning Zhang&#039;s Blog &#187; Design Time</title>
	<atom:link href="http://www.ningzhang.org/category/dt/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ningzhang.org</link>
	<description>About Silverlight, Microsoft technologies, and software development in general.</description>
	<lastBuildDate>Thu, 14 Apr 2011 22:47:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Silverlight Design Time Assemblies</title>
		<link>http://www.ningzhang.org/2009/11/30/silverlight-design-time-assemblies/</link>
		<comments>http://www.ningzhang.org/2009/11/30/silverlight-design-time-assemblies/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 10:07:02 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/2009/11/30/silverlight-design-time-assemblies/</guid>
		<description><![CDATA[Introduction If you write Silverlight controls, you should consider writing design time assemblies for your controls too, for two simple reasons: developer productivity: try to imagine Silverlight development without tools like Visual Studio or Blend! For custom controls, you may need to provide much of the design time experience for your controls in Visual Studio [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>If you write Silverlight controls, you should consider writing design time assemblies for your controls too, for two simple reasons:</p>
<ul>
<li>developer productivity: try to imagine Silverlight development without tools like Visual Studio or Blend! For custom controls, you may need to provide much of the design time experience for your controls in Visual Studio or Blend yourself. </li>
<li>designers: XAML and tools like Blend enable developers and designers work together. A key design criteria for Silverlight controls is to make sure designers can use them without writing a single line of code. </li>
</ul>
<p>Design time experience usually includes (but not limited to) the following:</p>
<ol>
<li>Metadata for property window, like category, infotip, custom property/binding/collection editors etc. </li>
<li>Metadata for design surface, like initializer, adorner, context menu, adapters etc. </li>
<li>Toolbox integration, like icons, control registration </li>
<li>intellisense for code editor </li>
</ol>
<p>Except intellisense (please see <a href="http://www.ningzhang.org/2009/04/22/add-rich-intellisense-for-your-silverlight-controls/" target="_blank">Add Rich Intellisense for Your Silverlight Controls</a>) and control registration (please see <a href="http://www.ningzhang.org/2009/04/30/register-silverlight-controls-with-visual-studio-and-blend/" target="_blank">Register Silverlight Controls with visual Studio and Blend</a>), above design time experience are usually delivered through design time assemblies. Below I will discuss various approaches of delivering design time experiences, in increasing complexity and flexibility, and gradually introduce pieces of the naming convention for design time assemblies. </p>
<h3>Runtime Assembly Only</h3>
<p>The simplest way to deliver design time experience is to package design time code into the runtime assemblies, especially when design time metadata are meaningful at runtime too, like <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverterattribute.aspx" target="_blank">TypeConverterAttribute</a>. </p>
<p>The pros and cons of this approach:</p>
<ul>
<li>Pro: simple
<ul>
<li>no separate design time assemblies, simpler setup </li>
<li>design time attributes are specified directly on the runtime code, easier to maintain </li>
</ul>
</li>
<li>Con: tight coupling of runtime and design time code
<ul>
<li>perf degradation because of useless design time code at runtime </li>
<li>design time dependencies (like MWDs and other VS/Blend assemblies) get dragged into runtime unnecessarily </li>
<li>can’t service runtime or design time independently </li>
<li>can’t support multiple designers (like both VS2008/Blend2 and VS2010/Blend3) </li>
</ul>
</li>
</ul>
<p>The cons are particularly bad for Silverlight, because design time assemblies are actually .NET assemblies, with references to Silverlight types. Mixing Silverlight and .NET assemblies can be challenging and confusing, and may lead to subtle bugs. Also, Silverlight applications are mostly web applications, so download size and performance are particularly important. Dragging in .NET assemblies in Silverlight applications certainly doesn’t help. So this approach is highly discouraged, unless there is strong justification for it.</p>
<h3>Shared Design Time Assembly</h3>
<p>So the revolutionary step forward is to decouple design time and runtime code, release and service them with separate assemblies. This opens up all kinds of possibilities. Of course, we need a way to link design time assemblies to their corresponding runtime assemblies, without introducing any unnecessary dependency or perf degradation to runtime assemblies. Hence the naming convention: <em><strong>if a runtime assembly Foo.dll is referenced in a Silverlight project, the designer </strong>(like Visual Studio and Blend)<strong> will first try to load design time information </strong>like icons (via another naming convention, see </em><a href="http://www.ningzhang.org/2009/01/21/how-to-add-an-toolbox-icon-for-your-silverlight-control/" target="_blank"><em>How to Add an Toolbox Icon for Your Silverlight Control</em></a><em>) and design time metadata (via interface, like </em><a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.iregistermetadata.aspx" target="_blank"><em>IRegisterMetadata</em></a><em> for VS2008 and Blend2, or IProvideAttributeTable for VS2010 and Blend3. Please see </em><a href="http://www.ningzhang.org/2009/03/31/how-to-write-silverlight-design-time-for-all-designers-visual-studio-2008-blend-2-blend-3-and-visual-studio-2010/" target="_blank"><em>How to Write Silverlight Design Time for All Designers: Visual Studio 2008, Blend 2; Blend 3, and Visual Studio 2010</em></a><em>) <strong>from the runtime assembly; it will then look for a design time assembly by the name Foo.Design.dll in the same directory as Foo.dll; if found, the designer will try to load design time information from Foo.Design.dll as well.</strong></em> </p>
<h3>Designer Specific Design Time Assembly</h3>
<p>Visual Studio is mostly for developers, while Blend is mostly for designers, so they have different requirements for design time experiences. Putting all design time code in one shared design time assembly introduces tight coupling among designers. So the naming convention is enhanced: <strong><em>for runtime assembly Foo.dll, there is a shared design time assembly Foo.Design.dll that’s loaded by all designers; each designer will also try to load its own design time assemblies, like Foo.VisualStudio.Design.dll for Visual Studio, and Foo.Expression.Design.dll for Blend. The designer specific design time assembly is loaded after the shared design time assembly. </em></strong>Third party designers can define their own designer specific design time assembly. <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=19172" target="_blank">Silverlight Toolkit December 2008 Release</a> is using this naming convention. Please see <a href="http://www.ningzhang.org/2008/12/13/design-time-features-in-silverlight-toolkit/" target="_blank">Design Time Features in Silverlight Toolkit</a> and <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> for more information. </p>
<h4>Design Sub Folder</h4>
<p>So to support both Visual Studio and Blend, each runtime assembly has three design time assemblies, in the same directory, and a package (like Silverlight SDK or <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a>) usually contains several runtime assemblies. So the directory gets a bit crowded. A minor improvement is to put the design time assemblies under a Design subfolder. So the naming convention is further enhanced: <strong><em>if a designer (like Visual Studio or Blend) can’t find corresponding design time assemblies in the same directory as a runtime assembly, it will look for them in the Design subfolder, if it exists.</em></strong>&#160;</p>
<h3>Support Multiple Versions of MWDs</h3>
<p>Design time are built on top of <a href="http://msdn.microsoft.com/en-us/library/bb546938(VS.100).aspx" target="_blank">designer extensibility framework</a>, which consists of several dlls like Microsoft.Windows.Design.Extensibility.dll and Microsoft.Windows.Design.Interaction.dll. We usually call them collectively as MWDs. To make life more interesting, sometimes we have to introduce breaking changes to the extensibility framework, like VS2008 and Blend2 use MWD version 3.5, VS2010 and Blend3 use MWD version 4.0, and they are incompatible. So if you have a runtime assembly Foo.dll, and you want your users to be able to develop against it with both VS2008 and VS2010, you have to provide two sets of design time assemblies: one set built against v3.5 MWDs and used by VS2008, and another set built against v4.0 MWD and used by VS2010. The two sets of design time assemblies probably have a lot of code in common, while the one for VS2010 may have some new code to leverage the new functionalities exposed by VS2010. Since design time assemblies are loaded by name and you can’t have two files with the same name, so the naming convention is enhanced yet again:</p>
<p><strong><em>for a runtime assembly Foo.dll, the shared design time assembly is named Foo.Design*.dll, the Visual Studio specific design time assembly is named Foo.VisualStudio.Design*.dll, and the Blend specific design time assembly is named Foo.Expression.Design*.dll, where * can be zero or more valid characters for file names. When a designer (like Visual Studio or Blend) tries to load a design time assembly and several fit the naming convention, zero or one will be loaded:</em></strong></p>
<ul>
<li><strong><em>If the MWD version referenced by the design-time assembly has a different major version number than the designer’s MWD version, then the design-time assembly will not load and is bypassed. </em></strong></li>
<li><strong><em>If more than one design-time assembly is compatible with the designer’s MWD version, the Designer loads the one compiled against the highest MWD version that is less than or equal to the designer’s MWD version.</em></strong> </li>
</ul>
<p><a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30514" target="_blank">Silverlight 3 Toolkit October 2009 Release</a> uses this naming convention to support both VS2008 and Blend3/VS2010. Please see <a href="http://www.ningzhang.org/2009/10/21/silverlight-design-time-toolkit-october-2009-release-update/" target="_blank">Silverlight Design Time: Toolkit October 2009 Release Update</a>, <a href="http://www.ningzhang.org/2009/03/31/how-to-write-silverlight-design-time-for-all-designers-visual-studio-2008-blend-2-blend-3-and-visual-studio-2010/" target="_blank">How to Write Silverlight Design Time for All Designers: Visual Studio 2008, Blend 2; Blend 3, and Visual Studio 2010</a>, and <a href="http://karlshifflett.wordpress.com/2009/11/20/extensibility-series-wpf-silverlight-design-time-code-sharing-part-i/" target="_blank">Extensibility Series – WPF &amp; Silverlight Design-Time Code Sharing – Part I</a> more information. </p>
<h3>Support Both WPF and Silverlight</h3>
<p>To complicate life further, since WPF and Silverlight are so awfully similar, you may be tempted to try to write it once and run with both WPF and Silverlight. You are not alone. There are many articles on how to share source code and/or binaries across Silverlight and WPF. We’d like to do that for design time assemblies too, i.e. have the same design time assemblies for both WPF and Silverlight controls. One approach is to make most of the design time assemblies platform agnostic, and limit platform specific (WPF or Silverlight) code and references to a small platform specific assembly. <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=1ea49236-0de7-41b1-81c8-a126ff39975b&amp;displaylang=en" target="_blank">Silverlight 3 SDK GDR 2</a> (installed by VS2010 automatically too) uses this approach for DataGrid designer (there is a System.Windows.Controls.Data.VisualStudio.Design.4.0.Silverlight.dll in the SDK directory). Please see <a href="http://karlshifflett.wordpress.com/2009/11/20/extensibility-series-wpf-silverlight-design-time-code-sharing-part-i/" target="_blank">Extensibility Series – WPF &amp; Silverlight Design-Time Code Sharing – Part I</a> for more information. </p>
<h3>Last One Wins</h3>
<p>The same design time metadata for a class or its member can be specified multiple times in multiple design time assemblies, which allows the shared design time assembly to specify default/common behavior and then designer specific design time assemblies to override it if necessary. The same design time metadata can also be specified multiple times within a single design time assembly (please see <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> as an example, where <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx" target="_blank">DescriptionAttribute</a> for a class or its property can be added by AddDescriptions, AddAttributes and AddTables methods). So we need to know which metadata wins. The simplest and most logic design is <strong>last one wins</strong>. This is mostly true but not always. Sometimes the result can be un-deterministic when the same design time metadata is specified several times but with different values. </p>
<h3>Feedback</h3>
<p>Design time sounds easy, but devil is in the details! Feedbacks are always appreciated. Please let me know what issues you run into, what requests/improvements you’d like to make, for both design times experience and designer extensibility framework. Thanks!</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7610ba0f-16e0-4a96-8b2b-8cf4dface553" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Design+Time" rel="tag">Design Time</a>,<a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a>,<a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/Visual+Studio" rel="tag">Visual Studio</a>,<a href="http://technorati.com/tags/Blend" rel="tag">Blend</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/11/30/silverlight-design-time-assemblies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight Design Time: Toolkit October 2009 Release Update</title>
		<link>http://www.ningzhang.org/2009/10/21/silverlight-design-time-toolkit-october-2009-release-update/</link>
		<comments>http://www.ningzhang.org/2009/10/21/silverlight-design-time-toolkit-october-2009-release-update/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 01:18:20 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/2009/10/21/silverlight-design-time-toolkit-october-2009-release-update/</guid>
		<description><![CDATA[Overview Visual Studio 2010 Beta 2 is available now. For Silverlight developers, the most exciting news about VS2010 is that Silverlight designer will be in feature parity with WPF designer, and VS2010 will support multi-targeting for Silverlight development. Silverlight Toolkit team has been working closely with Cider team in providing the design time experience for [...]]]></description>
			<content:encoded><![CDATA[<h3>Overview</h3>
<p><a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">Visual Studio 2010 Beta 2</a> is available now. For Silverlight developers, the most exciting news about VS2010 is that Silverlight designer will be in feature parity with WPF designer, and VS2010 will support multi-targeting for Silverlight development. Silverlight Toolkit team has been working closely with Cider team in providing the design time experience for Silverlight SDK and Toolkit controls. The design time for Silverlight 3 SDK controls has been released with <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1EA49236-0DE7-41B1-81C8-A126FF39975B&amp;displaylang=en" target="_blank">SL3 SDK</a> in August 2009, and is also chain installed by VS2010 Beta2. The design time for Toolkit controls, together with sources for both SDK and Toolkit controls, and their design time, samples, unit tests etc, are in <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a>&#160;<a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30514" target="_blank">October 2009 Release</a>. We purposely made October 2009 release to be in sync with Visual Studio 2010 Beta 2 on Monday, 10/19/2009. This post demonstrates the new design time experiences for Silverlight controls in VS2010. </p>
<h3>Install</h3>
<p>VS2010 installs side by side with VS2008. Multiple releases of Toolkit install side by side too. So it is perfectly safe to install VS2010 and Toolkit October 2009 release on your main machine. The only caveat is that if you have a pre August 2009 version of Silverlight 3 SDK installed, you will need to uninstall it first, before installing VS2010. You can install VS2010 Beta2 from <a title="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx">http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx</a>, and Silverlight Toolkit from <a href="http://silverlight.codeplex.com">http://silverlight.codeplex.com</a>.</p>
<h3>Walkthrough</h3>
<p>The October 2009 release is for Silverlight 3 only. It provides design time support for both VS2008 and VS2010, as well as Blend 3. Below walkthrough will be VS2010 only. Design time experience for VS2008 and Blend 3 are similar to <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24246" target="_blank">July 2009 release</a>. Please see my previous posts for design time experience with VS2008 and Blend3.</p>
<ul>
<li>Create a new Silverlight Application project in VS2010, notice that:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3New2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create New Silverlight Application Project" border="0" alt="Create New Silverlight Application Project" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3New_thumb2.png" width="584" height="407" /></a>
<ul>
<li>the toolbox is populated with both SDK and Toolkit controls, with nice icons. If you have Blend3 installed before Toolkit, you may see a lot of Blend controls on the toolbox that are not supposed to. You can safely remove them by right click a control in the toolbox and select delete. </li>
<li>it is a real designer: both the design view and the properties window work! </li>
</ul>
</li>
<li>double click TabControl in the toolbox will add a tabControl1. Notice that:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabCtrlInit2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Tab Control from Toolbox" border="0" alt="Add Tab Control from Toolbox" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabCtrlInit_thumb2.png" width="584" height="404" /></a>
<ul>
<li>A reference to System.Windows.Controls.dll is added, together with a <font face="Lucida Console">xmlns definition: xmlns:controls=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls&quot;</font> </li>
<li>tabControl1 is initialized with a tabItem1, which itself is initialized with a header and &lt;Grid/&gt; content. (via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.defaultinitializer.aspx" target="_blank">DefaultInitializer</a>) </li>
<li>Property Items is selected in the Properties window (via <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultpropertyattribute.aspx" target="_blank">DefaultPropertyAttribute</a>) </li>
<li>Properties are categorized (via <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.categoryattribute.aspx" target="_blank">CategoryAttribute</a>), and have tooltip (via <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx" target="_blank">DescriptionAttribute</a>) </li>
</ul>
</li>
<li>Double click tabControl1 will add an event handler for SelectionChanged event (via <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.defaulteventattribute.aspx" target="_blank">DefaultEventAttribute</a>)       <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabDefEvent2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Default Event" border="0" alt="Default Event" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabDefEvent_thumb2.png" width="584" height="404" /></a> </li>
<li>right click tabControl1, select Add Tab (via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.interaction.primaryselectioncontextmenuprovider.aspx" target="_blank">PrimarySelectionContextMenuProvider</a>):       <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabAddTabCM2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3TabAddTabCM" border="0" alt="VS10SL3TabAddTabCM" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabAddTabCM_thumb1.png" width="584" height="404" /></a> </li>
<li>A new tabItem2 is added. Notice that:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabAddTabResult1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3TabAddTabResult" border="0" alt="VS10SL3TabAddTabResult" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabAddTabResult_thumb1.png" width="584" height="405" /></a>
<ul>
<li>tabItem2 is initialized with a &lt;Grid/&gt; content </li>
<li>tabItem2’s default property Header is highlighted. You can type into the text box next to it and change the object typed Header property directly. (via <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverterattribute.aspx" target="_blank">TypeConverterAttribute</a>) </li>
<li>all properties have nice infotip </li>
</ul>
</li>
<li>double click DatePicker on toolbox:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3DatePickerAdd1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3DatePickerAdd" border="0" alt="VS10SL3DatePickerAdd" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3DatePickerAdd_thumb1.png" width="584" height="404" /></a>
<ul>
<li>a datePicker1 is added to tabItem2’s &lt;Grid&gt; (via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.interaction.parentadapter.aspx" target="_blank">ParentAdapter</a>) </li>
<li>datePicker1 is fully expanded, even though its IsDropDownOpen property is false (via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.designmodevalueprovider.aspx" target="_blank">DesignModeValueProvider</a>) </li>
</ul>
</li>
<li>Now click tabItem1, notice that tabItem2’s content is hidden and tabItem1’s is shown:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabItemSelect1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3TabItemSelect" border="0" alt="VS10SL3TabItemSelect" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabItemSelect_thumb1.png" width="584" height="404" /></a> </li>
<li>click Chart on toolbox:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabAddChartpng1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3TabAddChartpng" border="0" alt="VS10SL3TabAddChartpng" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3TabAddChartpng_thumb1.png" width="584" height="408" /></a>
<ul>
<li>a chart1 is added to the right place, initialized with sample data, and nicely rendered </li>
<li>default property Series is selected in the properties window </li>
</ul>
</li>
<li>click the … button next to Series property to pop up the Collection Editor:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3ChartSeries1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3ChartSeries" border="0" alt="VS10SL3ChartSeries" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3ChartSeries_thumb1.png" width="584" height="353" /></a>
<ul>
<li>the Select item ComboBox is populated with the correct types (via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.newitemtypesattribute.aspx" target="_blank">NewItemTypesAttribute</a>). The pink background for the icons are fixed now. </li>
<li>the Properties window for the series highlights the default property DependentValuePath, have all properties categorized (like the Data Visualization category), and you can modify the object typed Title property directly in the text box. </li>
</ul>
</li>
<li>Create a simple data class with some simple properties, and add it as a data source, via Data |&#160; Show Data Sources menu item:&#160; <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3Binding11.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3Binding1" border="0" alt="VS10SL3Binding1" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3Binding1_thumb1.png" width="584" height="396" /></a> </li>
<li>Drag MyData over tabItem1’s header and drop it :      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3Binding21.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Data Binding" border="0" alt="Data Binding" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3Binding2_thumb1.png" width="584" height="398" /></a>
<ul>
<li>a CollectionViewDataSource is inserted, used as <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontext.aspx" target="_blank">DataContext</a> of the LayoutRoot, and tabItem1’s Header is bound to it. (Via <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultbindingpropertyattribute.aspx" target="_blank">DefaultBindingPropertyAttribute</a>) </li>
</ul>
</li>
<li>Just for fun, open the project in Blend 3, you will see very similar design time behaviors:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3Blend31.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS10SL3Blend3" border="0" alt="VS10SL3Blend3" src="http://www.ningzhang.org/wp-content/uploads/2009/10/VS10SL3Blend3_thumb1.png" width="584" height="439" /></a>&#160; </li>
<p> While VS2010 design time is the exciting new feature of this release, design time support for VS2008 and Blend 3 are still there and has lots of bug fixes. Please refer to previous post <a href="http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/" target="_blank">Silverlight Toolkit Design Time Features: March 2009 Release Update</a> for more information for VS2008 and Blend 3 design time experience. </ul>
<h3>Conclusion</h3>
<p>Above walkthrough is only a peek into all the design time features we have implemented for VS2010. I am very excited that VS2010 now provides a real designer for Silverlight, and I will continue enriching the design time experience for Silverlight in VS and Blend. Your feedback is welcome.</p>
<p>I will write a series of posts explaining how those design time experience are implemented.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:bfdefe3f-2272-4482-92ff-7ca1607220e9" class="wlWriterSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Silverlight+Toolkit" rel="tag">Silverlight Toolkit</a>,<a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a>,<a href="http://technorati.com/tags/Design+Time" rel="tag">Design Time</a>,<a href="http://technorati.com/tags/Visual+Studio+2010" rel="tag">Visual Studio 2010</a>,<a href="http://technorati.com/tags/Visual+Studio" rel="tag">Visual Studio</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/10/21/silverlight-design-time-toolkit-october-2009-release-update/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Silverlight Design Time: Toolkit July 2009 Release Update</title>
		<link>http://www.ningzhang.org/2009/09/29/silverlight-design-time-toolkit-july-2009-release-update/</link>
		<comments>http://www.ningzhang.org/2009/09/29/silverlight-design-time-toolkit-july-2009-release-update/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 22:38:19 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/2009/09/29/silverlight-design-time-toolkit-july-2009-release-update/</guid>
		<description><![CDATA[I have been very busy and haven’t post for a while, so this is a quick late post on Toolkit July 2009 Release. This release is the last Toolkit release for Silverlight 2: when a new version of Silverlight RTMs, we drop support for the previous version, so each Toolkit release needs to support at [...]]]></description>
			<content:encoded><![CDATA[<p>I have been very busy and haven’t post for a while, so this is a quick late post on Toolkit <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24246" target="_blank">July 2009 Release</a>. This release is the last Toolkit release for Silverlight 2: when a new version of Silverlight RTMs, we drop support for the previous version, so each Toolkit release needs to support at most two versions of Silverlight. As for design time feature updates, there have been a lot of improvements over <a href="http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/" target="_blank">March 2009 Release</a>. I will use a simple walkthrough to highlight a few noticeable new features: </p>
<ul>
<li>Install Silverlight 3, Blend 3 and Toolkit from <a href="http://silverlight.net/getstarted/">http://silverlight.net/getstarted/</a> </li>
<li>Open Blend 3, create a new Silverlight 3 Application project </li>
<li>Open Asset Library, notice few improvements:
<ul>
<li>the new Asset Library. See Unni’s blog <a href="http://blogs.msdn.com/unnir/archive/2009/05/22/the-blend-3-asset-library.aspx" target="_blank">The Blend 3 Asset Library</a> for more info.&#160; </li>
<li>the nicer icons and more informative infotip </li>
</ul>
</li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/09/image.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blend 3 Asset Library" border="0" alt="Blend 3 Asset Library" src="http://www.ningzhang.org/wp-content/uploads/2009/09/image_thumb.png" width="604" height="388" /></a> </p>
<ul>
<li>Add an Expander control, and set it as the new active container: </li>
</ul>
<p> <a href="http://www.ningzhang.org/wp-content/uploads/2009/09/image1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Pin Active Container " border="0" alt="Pin Active Container " src="http://www.ningzhang.org/wp-content/uploads/2009/09/image_thumb1.png" width="604" height="398" /></a>
<ul>
<li>Add a DatePicker to the Expander, notice that both the DatePicker and its Calendar drop down are shown, even though both Expander’s IsExpanded and DatePicker’s IsDropDownOpen are false. </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/09/image2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ningzhang.org/wp-content/uploads/2009/09/image_thumb2.png" width="604" height="389" /></a> </p>
<ul>
<li>Select LayoutRoot so Expander and the nest DatePicker are no longer selected, notice that both are now collapsed. </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/09/image3.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ningzhang.org/wp-content/uploads/2009/09/image_thumb3.png" width="604" height="389" /></a> </p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/09/image4.png" target="_blank"><img style="border-right-width: 0px; margin: 0px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Toolbox" border="0" alt="Visual Studio Toolbox" align="right" src="http://www.ningzhang.org/wp-content/uploads/2009/09/image_thumb4.png" width="206" height="663" /></a>Open the project in Visual Studio,notice that the Toolbox is populated with lots of controls from Silverlight SDK and Toolkit, with nice icons. </p>
<p>&#160;</p>
<p>So far, design time features for Silverlight are mostly exposed through Blend. This will change with next beta of Visual Studio 2010, which will come out soon, according to this Visual Studio Magazine <a href="http://visualstudiomagazine.com/Blogs/RDN-Express/2009/09/VS2010-and-.NET-4-Beta-2-Expected-Soon.aspx" target="_blank">article</a>. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/09/29/silverlight-design-time-toolkit-july-2009-release-update/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Editing Model &amp; Default Initializer for Silverlight Controls</title>
		<link>http://www.ningzhang.org/2009/05/11/editing-model-default-initializer-for-silverlight-controls/</link>
		<comments>http://www.ningzhang.org/2009/05/11/editing-model-default-initializer-for-silverlight-controls/#comments</comments>
		<pubDate>Mon, 11 May 2009 09:43:00 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[DefaultInitializer]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/2009/05/11/editing-model-default-initializer-for-silverlight-controls/</guid>
		<description><![CDATA[This is part of the series on design time feature implementation in Silverlight Toolkit. This post uses the Chart default initializer to illustrate how to implement default initializer for Silverlight controls, and explain the underlying editing model architecture.]]></description>
			<content:encoded><![CDATA[<p>
<link rel="stylesheet" type="text/css" href="http://www.ningzhang.org/codesnippet.css" />
</p>
<h3>Introduction</h3>
<p>This is part of the series on design time feature implementation in <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a>. This post uses the Chart default initializer to illustrate how to implement default initializer for Silverlight controls, and explain the underlying editing model architecture.</p>
<h3>Experience</h3>
<p>If you install <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430#DownloadId=62369" target="_blank">Silverlight 3 Toolkit</a> in <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>, you can drag the Chart control from Blend Asset Library and drop it onto designer surface, and you have a chart nicely initialized and rendered:</p>
<p><a href="http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart default initializer" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image26.png" alt="Chart default initializer" width="604" height="350" /></a></p>
<p>You can read more about it in prior post <a href="http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/" target="_blank">Silverlight Toolkit Design Time Features: March 2009 Release Update</a>.</p>
<h3>Architecture</h3>
<h4>DefaultInitializer</h4>
<p>It is actually pretty simple to provide a default initializer for a Silverlight control:</p>
<ul>
<li>implement a subclass of <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.defaultinitializer.aspx" target="_blank">DefaultInitializer</a>, and override its <a href="http://msdn.microsoft.com/en-us/library/bb532681.aspx" target="_blank">InitializeDefaults</a> function</li>
<li>associate the default initializer class with the control class via a <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.features.featureattribute.aspx" target="_blank">FeatureAttribute</a></li>
</ul>
<p>Below screenshot shows the implementation of DefaultInitializer abstract base class, and other classes in Microsoft.Windows.Design.Model namespace that will be discussed shortly:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/05/image12.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DefaultInitializer" src="http://www.ningzhang.org/wp-content/uploads/2009/05/image-thumb8.png" border="0" alt="DefaultInitializer" width="604" height="454" /></a></p>
<p>Initialization is done in InitializeDefaults override, and result is serialized into xaml. So the first step in implementing a default initializer is to define the desired xaml to be produced.</p>
<h4>Editing Model</h4>
<p>Once the result xaml is defined, I wish there is a higher level abstraction/method that would just take the xaml. But unfortunately we have to use a much lower level (thus more flexible and powerful) imperative API called editing model that consists of classes like <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelitem.aspx" target="_blank">ModelItem</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelproperty.aspx" target="_blank">ModelProperty</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelevent.aspx" target="_blank">ModelEvent</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelfactory.aspx" target="_blank">ModelFactory</a> and <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.services.modelservice.aspx" target="_blank">ModelService</a>. The MSDN page <a href="http://msdn.microsoft.com/en-us/library/bb514661.aspx" target="_blank">Editing Model Architecture</a> gives an basic overview:</p>
<blockquote><p>Your design-time implementation interacts with run-time controls though a programming interface called the editing model. The objects being designed are called editable objects.</p>
<p>Your controls are defined in Extensible Application Markup Language (XAML). You update the XAML for your controls programmatically by using the editing model.</p>
<p><img src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /><strong>Model, Wrapper, and View</strong></p>
<p><a></a></p>
<p>The editing model consists of three functional subunits: a model, a public wrapper that abstracts the model, and a view that represents the user interface (UI) of the model. The model and the view are separate, but the wrapper and model are closely related. The following illustration shows the relationship among the three subunits.</p>
<p><img src="http://i.msdn.microsoft.com/Bb514661.Cider_ModWrap(en-us,VS.90).png" alt="Model, ModelItem, and View relationships" /></p>
<p>The design environment uses the <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelitem.aspx">ModelItem</a> type to communicate with the underlying model. All changes are made to the <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelitem.aspx">ModelItem</a> wrappers, which affect the underlying model. This allows the model to be simple. The <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.model.modelitem.aspx">ModelItem</a> wrappers handle complex designer features, such as transaction support, undo tracking, and change notifications.</p></blockquote>
<p>Below class diagram may help explain interactions among core classes of the editing model:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/05/image13.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Editing Model Class Diagram" src="http://www.ningzhang.org/wp-content/uploads/2009/05/image-thumb9.png" border="0" alt="Editing Model Class Diagram" width="604" height="442" /></a></p>
<p>Use below xaml as an example:</p>
<p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" class="csharpcode"><span class="kwrd">&lt;</span><span class="html">UserControl</span>
    <span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    <span class="attr">xmlns:x</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml"</span>
    <span class="attr">x:Class</span><span class="kwrd">="ModelTest.Page"</span> <span class="attr">Width</span><span class="kwrd">="640"</span> <span class="attr">Height</span><span class="kwrd">="480"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span> <span class="attr">x:Name</span><span class="kwrd">="LayoutRoot"</span> <span class="attr">Background</span><span class="kwrd">="White"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">x:Name</span><span class="kwrd">="Button"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Rectangle</span> <span class="attr">x:Name</span><span class="kwrd">="Rectangle"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">UserControl</span><span class="kwrd">&gt;</span></pre>
</div>
</p>
<ul>
<li>ModelItem: assume variable <em>item </em>is the ModelItem for the Button control above,
<ul>
<li>Name is persisted as <em>x:Name</em> attribute in xaml: <em>item.Name = “Button” </em>is persisted in xaml as <em>x:Name = “Button”</em>.</li>
<li>ItemType is the Type object of the underlying control, and decides the tag used in xaml:<em> item.PropertyType == tyepof(Button)</em>, and the xaml tag is <em>&lt;Button /&gt;</em>.</li>
<li>Properties is the collection of properties, wrapped in ModelProperty type, of the underlying control. For example: <em>item[“ClickMode”] = ClickMode.Release </em>will be persisted in xaml as <em>ClickMode=&#8221;Release&#8221;</em>.</li>
<li>Content represents the Content property defined in ContentControl (and inherited by its subclasses): <em>item.Content </em>is the ModelItem representing the Rectangle object.</li>
<li>Source: when a ModelItem represents an element that’s a property of another element, Source is the ModelProperty wrapper of that property. For example, <em>item.Content.Value.Source == item.Content // the Rectangle</em>.</li>
<li>Events represents the collection of events of the underlying control, wrapped in ModelEvent type. From my debugging experience, it is always null, so it seems Events property is not yet supported by Blend3 for Silverlight3 yet.</li>
<li>Parent is the the logic parent of the underlying control, wrapped in ModelItem type. ex: item.Parent is the ModelItem for Grid.</li>
<li>Root is the ModelItem wrapper for root visual, ex: item.Root represents the UserControl.</li>
</ul>
</li>
<li>ModelProperty: assume variable <em>prop</em> is the ModelProperty for Button.Content, i.e. <em>prop = item.Content</em>,
<ul>
<li>Name is the name of the property of the underlying control. It is persisted in xaml as attribute name. ex: <em>prop.Name == “Content”</em>.</li>
<li>PropertyType is the Type object of the property of the underlying control this ModelProperty object represents. ex: <em>prop.PropertyType = typeof(object)</em>.</li>
<li>AttachedOwnerType is the Type object of the control that first defines the property this ModelProperty object represents. ex: <em>prop.AttachedOwnerType == typeof(ContentControl) // note: not Button.</em></li>
<li>Value is the value of the property of the underlying control, wrapped in ModelItem type. ex: prop.Value is the ModelItem representing the Rectangle object.</li>
<li>Parent is the control, wrapped in ModelItem type, of which the property belongs to. ex: <em>prop.Parent == item</em>.</li>
</ul>
</li>
<li>ModelEvent: as mentioned above, item.Events is always null, so it doesn’t seem that ModelEvent is supported in Blend3 for Silverlight3 yet. But assume it works, and variable evt is the ModelEvent for Button.Click, i.e., <em>evt = item.Events[“Click”]</em>,
<ul>
<li>Name is the name of the event. ex: evt.Name == “Click”.</li>
<li>EventType is the type of the event delegate, ex: <em>evt.EventType == typeof(RoutedEventHandler)</em>.</li>
<li>Handlers is the string collection of event handlers, ex: <em>evt.Handlers = new string[] { “Button_Click” }</em> will be persisted as <em>Click = “Button_Click”</em>. Note: this is pure speculation, since ModelEvent isn’t yet supported, and I don’t know whether/when/how it will be supported for Silverlight.</li>
<li>Parent is the control, wrapped in ModelItem type, of which this event belongs to. ex: <em>evt.Parent == item</em>.</li>
</ul>
</li>
</ul>
<h3>Implementation</h3>
<p>The Chart default initializer class ChartDefaultInitializer is implemented in ChartDefaultInitializer.cs, and registered in ChartMetadata.cs. Both files are in Controls.DataVisualization.Toolkit.Design.csproj of Silverlight.Controls.Design.sln. Please read prior post <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> for more information.</p>
<h4>Result XAML</h4>
<p>As the first step, define the result xaml to be produced by ChartDefaultInitializer:</p>
<p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Charting:Chart</span> <span class="attr">Title</span><span class="kwrd">="Chart Title"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Charting:Chart.DataContext</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">PointCollection</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Point</span> <span class="attr">X</span><span class="kwrd">="1"</span> <span class="attr">Y</span><span class="kwrd">="10"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Point</span> <span class="attr">X</span><span class="kwrd">="2"</span> <span class="attr">Y</span><span class="kwrd">="20"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Point</span> <span class="attr">X</span><span class="kwrd">="3"</span> <span class="attr">Y</span><span class="kwrd">="30"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Point</span> <span class="attr">X</span><span class="kwrd">="4"</span> <span class="attr">Y</span><span class="kwrd">="40"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">PointCollection</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Charting:Chart.Series</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">Charting:ColumnSeries</span> <span class="attr">ItemsSource</span><span class="kwrd">="{Binding}"</span>
                <span class="attr">DependentValuePath</span><span class="kwrd">="X"</span>
                <span class="attr">IndependentValuePath</span><span class="kwrd">="Y"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Charting:Chart.Series</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Charting:Chart.DataContext</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Charting:Chart</span><span class="kwrd">&gt;</span></pre>
 </div>
</p>
<h4>Registration</h4>
<p>Done in ChartMetadata.cs with following code:</p>
<div>
<pre id="codeSnippet" class="csharpcode">b.AddCustomAttributes(<span class="kwrd">new</span> FeatureAttribute(<span class="kwrd">typeof</span>(ChartDefaultInitializer)));</pre>
</div>
<h4>References</h4>
<p>See below screenshot:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/05/image14.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="References" src="http://www.ningzhang.org/wp-content/uploads/2009/05/image-thumb10.png" border="0" alt="References" width="544" height="454" /></a></p>
<p>Even though DefaultInitializer is defined in version 3.5 of Microsoft.Windows.Design.Interaction.dll (under %devenvdir%\PublicAssemblies, i.e. c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies on 32bit Windows), it is not supported by Blend2 or Visual Studio 2008 for Silverlight. It is supported by Blend3 and Visual Studio 2010, but they both switch to newer version of Microsoft.Windows.Design*.dll (3.7 for Blend 3 Preview, 4.0 for Blend 3 RTM and Visual Studio 2010), so we need to link against the newer version of MWDs. Please see prior post <a href="http://www.ningzhang.org/2009/03/31/how-to-write-silverlight-design-time-for-all-designers-visual-studio-2008-blend-2-blend-3-and-visual-studio-2010/" target="_blank">How to Write Silverlight Design Time for All Designers: Visual Studio 2008, Blend 2; Blend 3, and Visual Studio 2010</a> for more information.</p>
<p>Please also notice that reference to Silverlight’s System.Windows.dll is aliased, and the PointCollection is specifically called out to be the Silverlight one, not WPF’s. Since WPF and Silverlight share a lot of classes in same namespaces, <em>it is important that Silverlight types, not WPF’s, are used in creating ModelItem and ModelProperty in default initializer for Silverlight controls</em>.</p>
<h4>Collections</h4>
<p>Please note in below screenshot that while all other property value can be set via ModelProperty.SetValue:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/05/image15.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ChartDefaultInitializer" src="http://www.ningzhang.org/wp-content/uploads/2009/05/image-thumb11.png" border="0" alt="ChartDefaultInitializer" width="604" height="429" /></a></p>
<p>Chart.Series is of collection type (Collection&lt;Series&gt;), so its value has to be set by first creating a ModelItem via ModelFactory.CreateItem for the value, and then add the created ModelItem via ModelProperty.Collection.Add. Otherwise, even though the correct xaml may be generated, Blend won’t refresh to render the Chart control correctly, you have to reload the page to have it rendered correctly.</p>
<h4>ChartDefaultInitializer.cs</h4>
<p>
<div id="codeSnippetWrapper" class="csharpcode-wrapper">
<pre id="codeSnippet" class="csharpcode"><span class="rem">// (c) Copyright Microsoft Corporation.</span>
<span class="rem">// This source is subject to the Microsoft Public License (Ms-PL).</span>
<span class="rem">// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.</span>
<span class="rem">// All other rights reserved.</span>

<span class="kwrd">extern</span> alias Silverlight;
<span class="kwrd">using</span> System.Windows.Controls.DataVisualization.Charting;
<span class="kwrd">using</span> System.Windows.Controls.Design.Common;
<span class="kwrd">using</span> Microsoft.Windows.Design.Metadata;
<span class="kwrd">using</span> Microsoft.Windows.Design.Model;
<span class="kwrd">using</span> SSW = Silverlight::System.Windows;
<span class="kwrd">using</span> SSWD = Silverlight::System.Windows.Data;
<span class="kwrd">using</span> SSWM = Silverlight::System.Windows.Media;

<span class="kwrd">namespace</span> System.Windows.Controls.DataVisualization.Design
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Default initializer for chart. </span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">internal</span> <span class="kwrd">class</span> ChartDefaultInitializer : DefaultInitializer
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Sets the default property values for chart. </span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="item"&gt;Chart ModelItem.&lt;/param&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> InitializeDefaults(ModelItem item)
        {
            <span class="kwrd">string</span> propertyName;

            <span class="rem">// &lt;Charting:Chart Title="Chart Title"&gt;</span>
            propertyName = Extensions.GetMemberName&lt;Chart&gt;(x =&gt; x.Title);
            item.Properties[propertyName].SetValue(Properties.Resources.ChartTitle);

            <span class="rem">// &lt;Charting:Chart.DataContext&gt;</span>
            <span class="rem">//     &lt;PointCollection&gt;</span>
            <span class="rem">//         &lt;Point X="1" Y="10" /&gt;</span>
            <span class="rem">//         &lt;Point X="2" Y="20" /&gt;</span>
            <span class="rem">//         &lt;Point X="3" Y="30" /&gt;</span>
            <span class="rem">//         &lt;Point X="4" Y="40" /&gt;</span>
            <span class="rem">//     &lt;/PointCollection&gt;</span>
            <span class="rem">// &lt;/Charting:Chart.DataContext&gt;</span>

            SSWM::PointCollection defaultItemsSource = <span class="kwrd">new</span> SSWM::PointCollection();
            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 1; i &lt;= 4; i++)
            {
                defaultItemsSource.Add(<span class="kwrd">new</span> SSW::Point(i, 10 * i));
            }

            propertyName = Extensions.GetMemberName&lt;Chart&gt;(x =&gt; x.DataContext);
            item.Properties[propertyName].SetValue(defaultItemsSource);

            <span class="rem">// &lt;Charting:Chart.Series&gt;</span>
            <span class="rem">//     &lt;Charting:ColumnSeries ItemsSource="{Binding}"</span>
            <span class="rem">//         DependentValuePath="X"</span>
            <span class="rem">//         IndependentValuePath="Y" /&gt;</span>
            <span class="rem">// &lt;/Charting:Chart.Series&gt;</span>

            ModelItem columnSeries = ModelFactory.CreateItem(item.Context, <span class="kwrd">typeof</span>(ColumnSeries));
            propertyName = Extensions.GetMemberName&lt;ColumnSeries&gt;(x =&gt; x.ItemsSource);
            columnSeries.Properties[propertyName].SetValue(ModelFactory.CreateItem(columnSeries.Context, <span class="kwrd">typeof</span>(SSWD::Binding)));
            propertyName = Extensions.GetMemberName&lt;ColumnSeries&gt;(x =&gt; x.DependentValuePath);
            columnSeries.Properties[propertyName].SetValue(<span class="str">"X"</span>);
            propertyName = Extensions.GetMemberName&lt;ColumnSeries&gt;(x =&gt; x.IndependentValuePath);
            columnSeries.Properties[propertyName].SetValue(<span class="str">"Y"</span>);

            propertyName = Extensions.GetMemberName&lt;Chart&gt;(x =&gt; x.Series);
            item.Properties[propertyName].Collection.Add(columnSeries);
        }
    }
}</pre>
 </div>
</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:49cdd6b9-c83e-4dd1-bc75-612e7b84e51b" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Silverlight">Silverlight</a>,<a rel="tag" href="http://technorati.com/tags/Design">Design</a>,<a rel="tag" href="http://technorati.com/tags/DefaultInitializer">DefaultInitializer</a>,<a rel="tag" href="http://technorati.com/tags/ModelItem">ModelItem</a>,<a rel="tag" href="http://technorati.com/tags/ModelProperty">ModelProperty</a>,<a rel="tag" href="http://technorati.com/tags/ModelEvent">ModelEvent</a>,<a rel="tag" href="http://technorati.com/tags/ModelFactory">ModelFactory</a>,<a rel="tag" href="http://technorati.com/tags/ModelService">ModelService</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/05/11/editing-model-default-initializer-for-silverlight-controls/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Register Silverlight Controls with Visual Studio and Blend</title>
		<link>http://www.ningzhang.org/2009/04/30/register-silverlight-controls-with-visual-studio-and-blend/</link>
		<comments>http://www.ningzhang.org/2009/04/30/register-silverlight-controls-with-visual-studio-and-blend/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 08:31:44 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Blend 3]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[March 2009 Release]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/?p=343</guid>
		<description><![CDATA[change history: 4/30/2009: published for Visual Studio 2008 SP1, Blend 3 Preview, Silverlight 3 Beta 1, and Silverlight 3 Toolkit March 2009 Release. 11/29/2009: updated for Visual Studio 2010 Beta 2. I will keep the content up to date with latest version of Visual Studio, Blend &#38; Silverlight. Introduction This is part of the series [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>change history:</p>
<ul>
<li>4/30/2009: published for Visual Studio 2008 SP1, Blend 3 Preview, Silverlight 3 Beta 1, and <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430#DownloadId=62369" target="_blank">Silverlight 3 Toolkit March 2009 Release</a>. </li>
<li>11/29/2009: updated for <a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target="_blank">Visual Studio 2010 Beta 2</a>. </li>
</ul>
<p>I will keep the content up to date with latest version of Visual Studio, Blend &amp; Silverlight. </p>
<h3>Introduction</h3>
<p>This is part of the series on design time implementation changes in <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>. This post illustrates the integration of Silverlight Toolkit with Visual Studio and Blend 3 after running Silverlight 3 Toolkit March 2009 Installer, and explains how it is done, so you can register your Silverlight controls with Visual Studio and Blend too.</p>
<h3>Blend Integration</h3>
<p>After installing <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=11dc7151-dbd6-4e39-878f-5081863cbb5d&amp;displaylang=en" target="_blank">Silverlight 3 Beta1 Tools</a>, <a href="http://www.microsoft.com/expression/try-it/blendpreview.aspx" target="_blank">Blend 3 Preview</a>, and <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430#DownloadId=62369" target="_blank">Silverlight 3 Toolkit March 2009</a> (please see post <a href="http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/" target="_blank">Silverlight Toolkit Design Time Features: March 2009 Release Update</a>, Silverlight 3 Development with Visual Studio 2008 and Blend 3 section for more information), create a Silverlight 3 Application from Blend 3, we can see that Silverlight Toolkit controls show up automatically in <strong>Asset Library</strong>:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image24.png" target="_blank"><img title="Toolkit Controls in Asset Library, Controls Tab" alt="Toolkit Controls in Asset Library, Controls Tab" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb21.png" /></a></p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image25.png" target="_blank"><img title="Toolkit Controls in Asset Library, Custom Controls Tab" alt="Toolkit Controls in Asset Library, Custom Controls Tab" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb22.png" /></a></p>
<p>User can drag and drop Toolkit controls from Asset Library to design or xaml view, and Blend will automatically add assembly reference, xmlns prefix and xaml code, very convenient:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image26.png" target="_blank"><img title="Drag and Drop Chart control from Asset Library" alt="Drag and Drop Chart control from Asset Library" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb23.png" /></a></p>
<h3>Visual Studio Integration</h3>
<p>Open the project in Visual Studio, we can see that Toolkit controls show up automatically in Visual Studio <strong>Toolbox</strong>, and user can drag and drop controls from Toolbox to design or xaml view as well:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image30.png" target="_blank"><img title="Toolkit Controls in Visual Studio Toolbox" alt="Toolkit Controls in Visual Studio Toolbox" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb27.png" /></a></p>
<p>Besides Toolbox, Toolkit assemblies also show up in <strong>Add Reference</strong> dialog:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image12.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Reference Dialog" border="0" alt="Add Reference Dialog" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb11.png" width="644" height="374" /></a></p>
<p>and <strong>Choose Toolbox Items</strong> dialog:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb12.png" width="644" height="439" /></a></p>
<h3>Implementation</h3>
<p>The integration with Visual Studio and Blend is done via registry. If you open “Silverlight 3 Toolkit March 2009.msi” in <a href="http://msdn.microsoft.com/en-us/library/aa370557.aspx" target="_blank">Orca</a>, you can see the registration magic:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image14.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Silverlight 3 Toolkit March 2009.msi in Orca" border="0" alt="Silverlight 3 Toolkit March 2009.msi in Orca" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb13.png" width="644" height="200" /></a></p>
<h4>Register with Visual Studio</h4>
<h5>AssemblyFoldersEx</h5>
<p>Registering with Visual Studio is mostly done via [HKLM|HKCU]\Software\Microsoft\Microsoft SDKs\Silverlight\v3.0\AssemblyFoldersEx. The <a href="http://fisheye1.atlassian.com/browse/~raw,r=1.1/nant/nant/etc/Reference%20Resolution%20in%20Visual%20Studio.htm" target="_blank">References in Visual Studio</a> page has very good explanation on AssemblyFoldersEx and reference resolution. It is a bit outdated, and is for .net instead of Silverlight. But it is mostly right for Silverlight too, and shows the root of the new toolbox registration mechanism with Visual Studio <strong>2010</strong>. We’ve worked hard to rationalize the registration mechanism, consolidating and simplifying it across tools like msbuild, Visual Studio and Blend.</p>
<p>Take <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30514" target="_blank">Silverlight 3 Toolkit October 2009 release</a> as example:</p>
<blockquote><p>c:\&gt;reg query &quot;HKEY_LOCAL_MACHINE\software\Microsoft\Microsoft sdks\Silverlight\v3.0\AssemblyFoldersEx\SilverlightToolkit0910&quot; /s </p>
<p>HKEY_LOCAL_MACHINE\software\Microsoft\Microsoft sdks\Silverlight\v3.0\AssemblyFoldersEx\SilverlightToolkit0910      <br />&#160;&#160;&#160; <strong>(Default)</strong>&#160;&#160;&#160; REG_SZ&#160;&#160;&#160; C:\Program Files\Microsoft SDKs\Silverlight\v3.0\Toolkit\Oct09\Bin\ </p>
<p>HKEY_LOCAL_MACHINE\software\Microsoft\Microsoft sdks\Silverlight\v3.0\AssemblyFoldersEx\SilverlightToolkit0910\<strong>Toolbox</strong></p>
</blockquote>
<ol>
<li><em>AssemblyFolderBase</em> indicates the target framework platform. Above registry path &quot;\Software\Microsoft\Microsoft SDKs\Silverlight&quot; indicates Silverlight SDK. Other possible values of AssemblyFolderBase:
<ul>
<li>&quot;\Software\Microsoft\Microsoft SDKs\Windows&quot; </li>
<li>&quot;\Software\Microsoft\.NETFramework&quot; </li>
<li>&quot;\Software\Microsoft\.NETCompactFramework&quot; </li>
</ul>
</li>
<li><em>FrameworkVersion</em> indicates the version of the target framework. “v3.0” in above example indicates this is for Silverlight 3. For Silverlight 4, use “v4.0”. </li>
<li><em>AssemblyFoldersSuffix</em> describes the sub-target. “AssemblyFoldersEx” in above example tells build system how to resolve assembly references when path of the referenced assembly isn’t given. Other typical values of AssemblyFoldersSuffix:
<ul>
<li>“Install Path”: where Silverlight SDK is installed. </li>
<li>“ReferenceAssemblies”: where Silverlight SDK reference assemblies are installed. </li>
</ul>
</li>
<li>PackageName indicates the name of the package registered, and its default value indicates where it is installed. In above example, “SilverlightToolkit0910” indicates this is Silverlight Toolkit October 2009 release, and its default value of “C:\Program Files\Microsoft SDKs\Silverlight\v3.0\Toolkit\Oct09\Bin\” indicates where it is installed. With this registration, Toolkit assemblies will show up in Add Reference dialog and Choose Toolbox Items dialog, and they can be references by other Silverlight projects without hint path. </li>
<li><strong><em>Toolbox</em></strong>: the existence of Toolbox sub key tells Visual Studio 2010 to scan all assemblies under the install path of this package, and add all controls found to Visual Studio Toolbox, except those with ToolboxBrowsableAttribute(false) specified. </li>
</ol>
<h5>Toolbox Controls Installer (deprecated)</h5>
<p><a href="http://blogs.msdn.com/jnak" target="_blank">Jim Nakashima</a> blogged about <a href="http://msdn.microsoft.com/en-us/library/bb286995(VS.80).aspx" target="_blank">Toolbox Controls Installer</a> for WPF controls in his post <a href="http://blogs.msdn.com/jnak/archive/2007/09/26/have-you-seen-the-toolbox-controls-installer.aspx" target="_blank">Have you seen the Toolbox Controls Installer?</a> in 2007. Toolbox Controls Installer package is now part of Visual Studio 2008, but it doesn’t work for Silverlight because of a bug that is later fixed in Visual Studio 2010. Given the new <strong>AssemblyFoldersEx\Toolbox</strong> registration mechanism, there is no reason to use TCI with Visual Studio 2010 and later.</p>
<h4>Register with Blend</h4>
<p>Registering with Blend is via HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Expression\Blend\v3.0\Toolbox\Silverlight\v3.0:</p>
<blockquote><p>c:\&gt;reg query &quot;hklm\software\Microsoft\expression\blend\3.0\toolbox\Silverlight\v3.0\SilverlightToolkit0910&quot; /s </p>
<p>HKEY_LOCAL_MACHINE\software\Microsoft\expression\blend\3.0\toolbox\Silverlight\v3.0\SilverlightToolkit0910     <br />&#160;&#160;&#160; (Default)&#160;&#160;&#160; REG_SZ&#160;&#160;&#160; C:\Program Files\Microsoft SDKs\Silverlight\v3.0\Toolkit\Oct09\Bin\</p>
</blockquote>
<p><a href="http://blogs.msdn.com/unnir" target="_blank">Unni Ravindranathan</a>’s blog post <a href="http://blogs.msdn.com/unnir/archive/2009/03/17/blend-3-extensibility.aspx" target="_blank">Blend 3 Extensibility</a> has more information about this mechanism. You can kind of mapping this registration mechanism to above Visual Studio registration mechanism: </p>
<ul>
<li>AssemblyFolderBase is “\Software\Microsoft\Expression\Blend\v3.0\Toolbox\Silverlight”</li>
<li>FrameworkVersion is “3.0”</li>
<li>PackageName is “SilverlightToolkit0910”, and its default value “C:\Program Files\Microsoft SDKs\Silverlight\v3.0\Toolkit\Oct09\Bin\” indicates where it is installed.</li>
</ul>
<p>One caveat: if the registered assemblies depend on other assemblies, those dependent assemblies need to be in the same directory as registered assemblies, or themselves registered under AssemblyFoldersEx as described above.</p>
<h3>Conclusion</h3>
<p>Registration with Visual Studio and Blend makes Silverlight Toolkit controls a lot easier to use for developers. We are constantly looking at improving the registration mechanism in hope to make it simple and consistent across designers (Visual Studio and Blend) and technologies (WPF and Silverlight). All feedbacks are welcome!</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:71331809-5a39-4407-b5dd-dd544c98fdde" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a>,<a href="http://technorati.com/tags/Visual+Studio" rel="tag">Visual Studio</a>,<a href="http://technorati.com/tags/Blend" rel="tag">Blend</a>,<a href="http://technorati.com/tags/msbuild" rel="tag">msbuild</a>,<a href="http://technorati.com/tags/AssemblyFoldresEx" rel="tag">AssemblyFoldresEx</a>,<a href="http://technorati.com/tags/Toolbox" rel="tag">Toolbox</a>,<a href="http://technorati.com/tags/Asset+Library" rel="tag">Asset Library</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/04/30/register-silverlight-controls-with-visual-studio-and-blend/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Add Rich Intellisense for Your Silverlight Controls</title>
		<link>http://www.ningzhang.org/2009/04/22/add-rich-intellisense-for-your-silverlight-controls/</link>
		<comments>http://www.ningzhang.org/2009/04/22/add-rich-intellisense-for-your-silverlight-controls/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 06:49:43 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Intellisense]]></category>
		<category><![CDATA[Silverlight SDK]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/?p=323</guid>
		<description><![CDATA[This post describes the rich intellisense support of Silverlight Toolkit and its implementation workflow from xmldoc comments to intellisense xml files to design dlls. ]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>This is part of the series on design time implementation changes in <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>. This post illustrates the rich  intellisense support for <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a>, and explains implementation workflow from  xmldoc in source to infotip in intellisense xml file and design assemblies.</p>
<h4>Intellisense</h4>
<p><a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> has rich Intellisense in code and XAML editors in both Visual Studio and Blend:</p>
<ul>
<li>Visual Studio Code Editor: <a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image34.png" target="_blank"><br />
<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS2008 Code Editor Intellisense" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image34-thumb.png" border="0" alt="VS2008 Code Editor Intellisense" width="604" height="402" /></a></li>
<li>Blend 3 Code Editor: <a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image30.png" target="_blank"><br />
<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blend 3 Code Editor Intellisense" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image30-thumb.png" border="0" alt="Blend 3 Code Editor Intellisense" width="604" height="389" /></a></li>
<li>Blend 3 XAML editor: <a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image26.png" target="_blank"><br />
<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blend 3 Xaml Editor Intellisense" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image26-thumb.png" border="0" alt="Blend 3 Xaml Editor Intellisense" width="604" height="389" /></a></li>
</ul>
<p>Visual Studio XAML editor has intellisense too, but no infotip:<br />
<a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Xaml Editor Intellisense" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb6.png" border="0" alt="Visual Studio Xaml Editor Intellisense" width="644" height="429" /></a><br />
 </p>
<h4>Implementation</h4>
<h5>Code Editor Intellisense Infotip from XML Files</h5>
<p>The intellisense infotips in code editors in Visual Studio and Blend come from intellisense xml files installed under Silverlight SDK and Toolkit directories:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image7.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Intellisense xml files installed" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb7.png" border="0" alt="Intellisense xml files installed" width="644" height="373" /></a></p>
<h5>Localization</h5>
<p>Those intellisense xml files can be localized. If you install localized  Visual Studio and localized Silverlight SDK, you will see localized infotips,  which is a great help for those who don’t speak English. Below is the screenshot  of Visual Studio running with Simplified Chinese language and <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&amp;FamilyID=c22d6a7b-546f-4407-8ef6-d60c8ee221ed" target="_blank">simplified Chinese version of Silverlight Tools for Visual Studio  SP1</a>:<br />
 </p>
<p><img class="size-full wp-image-330 alignnone" title="Chinese Visual Studio and Infotip" src="http://www.ningzhang.org/wp-content/uploads/2009/04/vschs.jpg" alt="Chinese Visual Studio and Infotip" width="640" height="484" /></p>
<p>The Chinese infotip is from localized System.Windows.Controls.xml under zh-CHS  sub directory:</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client&gt;dir/s /b system.windows.controls.xml
C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client\system.windows.controls.xml
C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Client\zh-CHS\system.windows.controls.xml</pre>
</div>
<h5>XAML Editor Intellisense Infotip from Design Assemblies</h5>
<p>The intellisense infotips in Blend 3 XAML editor come from a different mechanism: they come from <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx" target="_blank">DescriptionAttribute</a> implemented by design dlls installed under the Design subdirectory:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image8.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SDK Design Directory" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb8.png" border="0" alt="image" width="644" height="462" /></a></p>
<p>So it is the same as infotips in Blend Properties panel (please see <a href="http://www.ningzhang.org/2008/12/13/design-time-features-in-silverlight-toolkit/" target="_blank">Design Time Features in Silverlight Toolkit</a> for more information):</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blend Property Inspector Infotip" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb9.png" border="0" alt="Blend Property Inspector Infotip" width="644" height="415" /></a> </p>
<h5>xmldoc comment –&gt; intellisense xml file –&gt; DescriptionAttribute in design assembly</h5>
<p>All those infotips come from <a href="http://msdn.microsoft.com/en-us/library/b2s063f7.aspx" target="_blank">xml documentation comments</a> in source code, as seen from below screenshot:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image10.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Infotip workflow: from xmldoc to intellisense file to design dll" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb10.png" border="0" alt="image" width="588" height="484" /></a></p>
<ol>
<li>we put xmldoc comments in source code</li>
<li>build generates .xml files from those xmldoc comments</li>
<li>the generated .xml files are embedded in design dlls (see <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> for more information)</li>
<li>the control dlls, design dlls, and xml files are installed by SDK and Toolkit setup</li>
</ol>
<h4>Conclusion</h4>
<p>This post describes the rich intellisense support of <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> and its implementation workflow from xmldoc comments to intellisense xml files to design dlls. Good commenting pays!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/04/22/add-rich-intellisense-for-your-silverlight-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Property Value Editors for Silverlight Controls</title>
		<link>http://www.ningzhang.org/2009/04/03/property-value-editors-for-silverlight-controls/</link>
		<comments>http://www.ningzhang.org/2009/04/03/property-value-editors-for-silverlight-controls/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 19:24:34 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[PropertyValueEditor]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[TypeConverter]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/?p=301</guid>
		<description><![CDATA[This is part of the series on design time implementation in Silverlight Toolkit. This post discusses how to enhance property editing experience for Silverlight controls using property value editor and type converter. I will start with describing the overall property editing architecture in WPF/Silverlight designer extensibility framework, then use examples in  Silverlight Toolkit March 2009 Release to demonstrate how it is done, and unique issues/tricks in Silverlight design time development.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>This is part of the series on design time implementation changes in <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>. This post discusses how to enhance property editing experience for Silverlight controls using property value editor and type converter. I will start with describing the overall property editing architecture in WPF/Silverlight designer extensibility framework, then use examples in  <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a> to demonstrate how it is done, and unique issues/tricks in Silverlight design time development.</p>
<h3>Property Editing Architecture</h3>
<p>Visually editing object properties is an important part of designers. Designers usually don’t know how to render properties of custom type (struct, class or interface), much less to provide an nice editing user interface. Control developers usually need to provide <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx" target="_blank">TypeConverter</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.aspx" target="_blank">PropertyValueEditor</a>, or both, to provide rendering/editing UI and XAML serialization for properties of custom types.</p>
<p>The designer extensibility framework defines three types of property value editor: inline editor, extended editor, and dialog editor, each implemented by a class:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PropertyValueEditor class diagram" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb.png" border="0" alt="PropertyValueEditor class diagram" width="644" height="137" /></a></p>
<p>Editing UI of those editors are defined by <a href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx" target="_blank">DataTemplate</a>. The property being edited is exposed to editor as <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontext.aspx" target="_blank">DataContext</a> of <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalue.aspx" target="_blank">PropertyValue</a> type. Editor UI usually bind to the underlying property being edited via one of the three properties of <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalue.aspx" target="_blank">PropertyValue</a>: <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalue.value.aspx" target="_blank">Value</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalue.stringvalue.aspx" target="_blank">StringValue</a>, or <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalue.collection.aspx" target="_blank">Collection</a>.</p>
<h4>PropertyValueEditor</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.aspx" target="_blank">PropertyValueEditor</a> holds a single inline editor defined by <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.inlineeditortemplate.aspx" target="_blank">InlineEditorTemplate</a> property. Inline editor appears inside the properties window. Below is an simple example of <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.inlineeditortemplate.aspx" target="_blank">InlineEditorTemplate</a> that uses a TextBox to display and edit a property:</p>
<div>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">="TextBoxEditor"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding Path=Value}"</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre>
</div>
<div> </div>
<h4>ExtendedPropertyValueEditor</h4>
<div><a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.extendedpropertyvalueeditor.aspx" target="_blank">ExtendedPropertyValueEditor</a> has two editors: an inline editor inherited from <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.aspx" target="_blank">PropertyValueEditor</a>, and an additional extended editor defined by the <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.extendedpropertyvalueeditor.extendededitortemplate.aspx" target="_blank">ExtendedEditorTemplate</a> property. The extended editor is usually popped up by inline editor via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditorcommands.aspx" target="_blank">PropertyValueEditorCommands</a>.<a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditorcommands.showextendedpinnededitor.aspx" target="_blank">ShowExtendedPinnedEditor</a> or <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditorcommands.aspx" target="_blank">PropertyValueEditorCommands</a>.<a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditorcommands.showextendedpopupeditor.aspx" target="_blank">ShowExtendedPopupEditor</a> command. Below is a simple example: the inline editor is a button; when clicked, it pops up the extended editor that uses a Slider to display and edit the underlying property.</div>
<div class="csharpcode-wrapper">
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">="inlineEditor"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Content</span><span class="kwrd">="..."</span> <span class="attr">Command</span><span class="kwrd">="{x:Static PropertyEditing:PropertyValueEditorCommands.ShowDialogEditor}"</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">="extendedEditor"</span> <span class="attr">xmlns:PropertyEditing</span><span class="kwrd">="clr-namespace:Microsoft.Windows.Design.PropertyEditing;assembly=Microsoft.Windows.Design.Interaction"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Slider</span> <span class="attr">x:Name</span><span class="kwrd">="slider"</span> <span class="attr">Value</span><span class="kwrd">="{Binding Path=Value}"</span> <span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre>
</div>
<div> </div>
<h4>DialogPropertyValueEditor</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.dialogpropertyvalueeditor.aspx" target="_blank">DialogPropertyValueEditor</a> has two editors too: the inline editor inherited from <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.aspx" target="_blank">PropertyValueEditor</a>, and an additional dialog editor defined by <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.dialogpropertyvalueeditor.dialogeditortemplate.aspx" target="_blank">DialogEditorTemplate</a> property. The dialog editor is usually popped up by inline editor via <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditorcommands.aspx" target="_blank">PropertyValueEditorCommands</a>.<a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditorcommands.showdialogeditor.aspx" target="_blank">ShowDialogEditor</a> command. Below is a simple example:</p>
<div class="csharpcode-wrapper" style="width: 97.5%; height: 246px;">
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">="inlineEditor"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">Content</span><span class="kwrd">="..."</span> <span class="attr">Command</span><span class="kwrd">="{x:Static PropertyEditing:PropertyValueEditorCommands.ShowDialogEditor}"</span><span class="kwrd">/&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">DataTemplate</span> <span class="attr">x:Key</span><span class="kwrd">="dialogEditor"</span> <span class="attr">xmlns:PropertyEditing</span><span class="kwrd">="clr-namespace:Microsoft.Windows.Design.PropertyEditing;assembly=Microsoft.Windows.Design"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="Auto"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">ColumnDefinition</span> <span class="attr">Width</span><span class="kwrd">="*"</span> <span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="*"</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span class="html">RowDefinition</span> <span class="attr">Height</span><span class="kwrd">="*"</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;/</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Text</span><span class="kwrd">="User Name:"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Center"</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">="Right"</span> <span class="attr">Margin</span><span class="kwrd">="0,0,4,4"</span><span class="kwrd">/&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">TextBox</span> <span class="attr">Text</span><span class="kwrd">="{Binding Path=Value}"</span> <span class="attr">VerticalAlignment</span><span class="kwrd">="Center"</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">="Stretch"</span> <span class="attr">Margin</span><span class="kwrd">="0,0,4,4"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">Grid</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">DataTemplate</span><span class="kwrd">&gt;</span></pre>
</div>
<p> </p>
<p> </p>
<h4>Implement Custom Property Editor</h4>
<p>To implement a custom property editor for a Silverlight control:</p>
<ul>
<li>implement a custom property editor class
<ul>
<li>inherit from PropertyValueEditor, ExtendedPropertyValueEditor, or DialogPropertyValueEditor</li>
<li>set its editor template(s): <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.inlineeditortemplate.aspx" target="_blank">InlineEditorTemplate</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.extendedpropertyvalueeditor.extendededitortemplate.aspx" target="_blank">ExtendedEditorTemplate</a>, and/or <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.dialogpropertyvalueeditor.dialogeditortemplate.aspx" target="_blank">DialogEditorTemplate</a>;</li>
</ul>
</li>
<li>Associate the custom property editor with a property of a Silverlight control via a AddCustomAttributes call, something like
<div>
<pre class="csharpcode">attributeTableBuilder.AddCustomAttributes(
    <span class="kwrd">typeof</span>(MyControl),
    <span class="str">"MyProperty"</span>,
    <span class="kwrd">new</span> PropertyValueEditor.CreateEditorAttribute(<span class="kwrd">typeof</span>(MyValueEditor)));</pre>
<p> </p></div>
</li>
</ul>
<ul>A correctly implemented property value editor must satisfy the following requirements:   </p>
<li>The property value editor must be designed so that the inline editor and extended editor parts can be used independently.</li>
<li>A property value editor must not store state. Property value editors are stateless, might be cached by a host implementation, and can be re-used across multiple property values.</li>
<li>A property value editor must not assume that only one value editor part (view/inline/extended) control is active at a given time. For example, a dialog box could have the view part, inline part, and extended UI part active at the same time.</li>
<li>A control implemented as part of a property value editor must not store state. A control implemented as part of a value editor should not assume that it will only be bound to one property value. Controls may be recycled to change different property values. Any information that is cached should be flushed if the data model is updated.</li>
<li>A control implemented as part of a property value editor must not make any assumptions about the host or its parent controls. The only communication mechanisms that should be used are the <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalue.aspx" target="_blank">PropertyValue</a> data model, by way of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontext.aspx" target="_blank">DataContext</a>, and the standard set of commands.</li>
</ul>
<ul>You can read more about <a href="http://msdn.microsoft.com/en-us/library/bb514507.aspx" target="_blank">property editing architecture</a> and <a href="http://msdn.microsoft.com/en-us/library/bb546938.aspx" target="_blank">designer extensibility framework</a> on MSDN.</ul>
<ul> </ul>
<h3>Reference Both WPF and Silverlight Assemblies</h3>
<p>A design assembly is a .NET/WPF assembly loaded by Visual Studio or Blend, but it usually needs to reference Silverlight assemblies (at least the Silverlight control assembly it provides design time features for). This can create reference ambiguity for design assembly project: it sometimes needs to reference the same fully qualified type in both WPF and Silverlight, say System.Windows.FrameworkElement in both PresentationFramework.dll of WPF and System.Windows.dll of Silverlight. To avoid confusing Visual Studio, you can use <a href="http://msdn.microsoft.com/en-us/library/ms173212.aspx" target="_blank">extern alias</a> to distinguish WPF and Silverlight references.</p>
<p>For example, see the screenshot below for Controls.DataVisualization.Toolkit.Design project in Silverlight 3 Toolkit in <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb1.png" border="0" alt="image" width="644" height="460" /></a></p>
<ul>
<li>the project references both PresentationFramework and System.Windows, but System.Windows is under Silverlight alias, instead of the default global alias. The System.Windows reference under Silverlight alias is persisted in .csproj file as below:
<div class="csharpcode-wrapper">
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Reference</span> <span class="attr">Include</span><span class="kwrd">="System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, processorArchitecture=MSIL"</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">SpecificVersion</span><span class="kwrd">&gt;</span>False<span class="kwrd">&lt;/</span><span class="html">SpecificVersion</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">HintPath</span><span class="kwrd">&gt;</span>..\Binaries\System.Windows.dll<span class="kwrd">&lt;/</span><span class="html">HintPath</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">Private</span><span class="kwrd">&gt;</span>False<span class="kwrd">&lt;/</span><span class="html">Private</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">Aliases</span><span class="kwrd">&gt;</span>Silverlight<span class="kwrd">&lt;/</span><span class="html">Aliases</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">Reference</span><span class="kwrd">&gt;</span></pre>
<p> </p></div>
</li>
<li>in source code, we add
<div>
<pre class="csharpcode"><span class="kwrd">extern</span> alias Silverlight;
<span class="kwrd">using</span> SSW = Silverlight::System.Windows;</pre>
<p> </p></div>
<p>and reference Silverlight’s FrameworkElement via SSW::FrameworkElement.</li>
</ul>
<h3>TextBoxEditor</h3>
<p>There is a inline editor TextBoxEditor in Controls.DataVisualization.Toolkit.Design project for displaying and editing Title property of object type for  [Area|Bar|Bubble|Column|Line|Pie|Scatter]Series and Chart controls, as shown below:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image2.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TextBoxEditor" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb2.png" border="0" alt="TextBoxEditor" width="644" height="398" /></a></p>
<p>Text filled in Title field in Properties window on the right shows up automatically in XAML and design views in the middle.</p>
<p>The implementation of TextBoxEditor followed the steps outlined before:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image3.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TextBoxEditor.cs" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb3.png" border="0" alt="TextBoxEditor.cs" width="644" height="460" /></a></p>
<ul>
<li>TextBoxEditor is a subclass of PropertyValueEditor. It sets <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.propertyediting.propertyvalueeditor.inlineeditortemplate.aspx" target="_blank">InlineEditorTemplate</a> in its default constructor. Here I use code instead of XAML to construct the <a href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx" target="_blank">DataTemplate</a>, because somehow I can’t get xaml to build, and everything in XAML can be rewritten in C# anyway.</li>
<li>It is associated with Chart.Title in ChartMetadata.cs (see <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> for more information on *Metadata.cs files)</li>
</ul>
<p>TextBoxEditor.cs:</p>
<div class="csharpcode-wrapper">
<pre class="csharpcode"><span class="rem">// (c) Copyright Microsoft Corporation.</span>
<span class="rem">// This source is subject to the Microsoft Public License (Ms-PL).</span>
<span class="rem">// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.</span>
<span class="rem">// All other rights reserved.</span>

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> Microsoft.Windows.Design.PropertyEditing;
<span class="kwrd">using</span> System.Windows;
<span class="kwrd">using</span> System.Windows.Data;

<span class="kwrd">namespace</span> System.Windows.Controls.DataVisualization.Design
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Simple TextBox inline editor.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> TextBoxEditor : PropertyValueEditor
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Preserve the constructor prototype from PropertyValueEditor.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="inlineEditorTemplate"&gt;Inline editor template.&lt;/param&gt;</span>
        <span class="kwrd">public</span> TextBoxEditor(DataTemplate inlineEditorTemplate)
            : <span class="kwrd">base</span>(inlineEditorTemplate)
        { }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Default constructor builds the default TextBox inline editor template.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> TextBoxEditor()
        {
            FrameworkElementFactory textBox = <span class="kwrd">new</span> FrameworkElementFactory(<span class="kwrd">typeof</span>(TextBox));
            Binding binding = <span class="kwrd">new</span> Binding();
            binding.Path = <span class="kwrd">new</span> PropertyPath(<span class="str">"Value"</span>);
            binding.Mode = BindingMode.TwoWay;
            textBox.SetBinding(TextBox.TextProperty, binding);

            DataTemplate dt = <span class="kwrd">new</span> DataTemplate();
            dt.VisualTree = textBox;

            InlineEditorTemplate = dt;
        }
    }
}</pre>
</div>
<p> </p>
<h3>CultureInfoEditor</h3>
<p>My colleague <a href="http://www.sitechno.com/blog/" target="_blank">RJ</a> wrote inline editor CultureInfoEditor for TimePicker.Culture property, because the default editing experience for CultureInfo in Blend leads to invalid XAML. Below screenshot shows the CultureInfoEditor uses a ComboBox to display all CultureInfo and generates right XAML.</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image4.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CultureInfoEditor" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb4.png" border="0" alt="CultureInfoEditor" width="644" height="398" /></a></p>
<p>CultureInfoEditor is a more complex example than TextBoxEditor, really shows how the underlying property is associated with editor via DataContext property.</p>
<p>CultureInfoEditor.cs:</p>
<div class="csharpcode-wrapper">
<pre class="csharpcode"><span class="rem">// (c) Copyright Microsoft Corporation.</span>
<span class="rem">// This source is subject to the Microsoft Public License (Ms-PL).</span>
<span class="rem">// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.</span>
<span class="rem">// All other rights reserved.</span>

<span class="kwrd">using</span> System.Reflection;
<span class="kwrd">using</span> Microsoft.Windows.Design.PropertyEditing;
<span class="kwrd">using</span> System.Globalization;
<span class="kwrd">using</span> System.ComponentModel;

<span class="kwrd">namespace</span> System.Windows.Controls.Input.Design
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Editor for CultureInfo.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="rem">/// &lt;remarks&gt;Currently does not support binding from xaml to the editor.&lt;/remarks&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">class</span> CultureInfoEditor : PropertyValueEditor
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// The ComboBox being used to edit the value.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">private</span> ComboBox _owner;

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Preserve the constructor prototype from PropertyValueEditor.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="inlineEditorTemplate"&gt;Inline editor template.&lt;/param&gt;</span>
        <span class="kwrd">public</span> CultureInfoEditor(DataTemplate inlineEditorTemplate)
            : <span class="kwrd">base</span>(inlineEditorTemplate)
        { }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Default constructor builds a ComboBox inline editor template.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> CultureInfoEditor()
        {
            <span class="rem">// not using databinding here because Silverlight does not support</span>
            <span class="rem">// the WPF CultureConverter that is used by Blend.</span>
            FrameworkElementFactory comboBox = <span class="kwrd">new</span> FrameworkElementFactory(<span class="kwrd">typeof</span>(ComboBox));
            comboBox.AddHandler(
                ComboBox.LoadedEvent,
                <span class="kwrd">new</span> RoutedEventHandler(
                    (sender, e) =&gt;
                    {
                        _owner = (ComboBox) sender;
                        _owner.SelectionChanged += EditorSelectionChanged;
                        INotifyPropertyChanged data = _owner.DataContext <span class="kwrd">as</span> INotifyPropertyChanged;
                        <span class="kwrd">if</span> (data != <span class="kwrd">null</span>)
                        {
                            data.PropertyChanged += DatacontextPropertyChanged;
                        }
                        _owner.DataContextChanged += CultureDatacontextChanged;
                    }));

            comboBox.SetValue(ComboBox.IsEditableProperty, <span class="kwrd">false</span>);
            comboBox.SetValue(ComboBox.DisplayMemberPathProperty, <span class="str">"DisplayName"</span>);
            comboBox.SetValue(ComboBox.ItemsSourceProperty, CultureInfo.GetCultures(CultureTypes.SpecificCultures));
            DataTemplate dt = <span class="kwrd">new</span> DataTemplate();
            dt.VisualTree = comboBox;

            InlineEditorTemplate = dt;
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Handles the SelectionChanged event of the owner control.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; </span>
        <span class="rem">/// instance containing the event data.&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">void</span> EditorSelectionChanged(<span class="kwrd">object</span> sender, SelectionChangedEventArgs e)
        {
            <span class="rem">// serialize with name.</span>
                <span class="kwrd">object</span> DataContext = _owner.DataContext;
                DataContext
                    .GetType()
                    .GetProperty(<span class="str">"Value"</span>, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty)
                    .SetValue(DataContext, ((CultureInfo)_owner.SelectedItem).Name, <span class="kwrd">new</span> <span class="kwrd">object</span>[] { });
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Handles the PropertyChanged event of the context object.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="e"&gt;The &lt;see cref="System.ComponentModel.PropertyChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">void</span> DatacontextPropertyChanged(<span class="kwrd">object</span> sender, PropertyChangedEventArgs e)
        {
            <span class="rem">// deserialize from name.</span>
            <span class="kwrd">if</span> (e.PropertyName == <span class="str">"Value"</span>)
            {
                <span class="kwrd">object</span> <span class="kwrd">value</span> = sender
                    .GetType()
                    .GetProperty(<span class="str">"Value"</span>, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty)
                    .GetValue(sender, <span class="kwrd">new</span> <span class="kwrd">object</span>[] { });

                <span class="kwrd">if</span> (<span class="kwrd">value</span> != <span class="kwrd">null</span>)
                {
                    <span class="kwrd">if</span> (<span class="kwrd">value</span> <span class="kwrd">is</span> <span class="kwrd">string</span>)
                    {
                        CultureInfo setCulture = <span class="kwrd">new</span> CultureInfo(<span class="kwrd">value</span>.ToString());
                        _owner.SelectedItem = setCulture;
                    }
                }
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Called when the context is changed.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="rem">/// &lt;param name="sender"&gt;The sender.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="e"&gt;The &lt;see cref="System.Windows.DependencyPropertyChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">void</span> CultureDatacontextChanged(<span class="kwrd">object</span> sender, DependencyPropertyChangedEventArgs e)
        {
            INotifyPropertyChanged old = e.OldValue <span class="kwrd">as</span> INotifyPropertyChanged;
            <span class="kwrd">if</span> (old != <span class="kwrd">null</span>)
            {
                old.PropertyChanged -= DatacontextPropertyChanged;
            }
            INotifyPropertyChanged newDataContext = e.NewValue <span class="kwrd">as</span> INotifyPropertyChanged;
            <span class="kwrd">if</span> (newDataContext != <span class="kwrd">null</span>)
            {
                newDataContext.PropertyChanged += DatacontextPropertyChanged;
            }
        }
    }
}</pre>
</div>
<p> </p>
<h3>ExpandableObjectConverter</h3>
<p>As discussed at the beginning, besides custom property value editors, sometimes you can use appropriate type converter to provide good editing experience and XAML serialization. One example is ColumnSeries.DependentRangeAxis: it is of IRangeAxis type, Blend doesn’t know how to edit it, so it shows DependentRangeAxis as read only in Properties Panel. By associating <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.expandableobjectconverter.aspx" target="_blank">ExpandableObjectConverter</a> to ColumnSeries.DependentRangeAxis:</p>
<div>
<pre class="csharpcode">b.AddCustomAttributes(
    Extensions.GetMemberName&lt;ColumnSeries&gt;(x =&gt; x.DependentRangeAxis),
    <span class="kwrd">new</span> TypeConverterAttribute(<span class="kwrd">typeof</span>(ExpandableObjectConverter)));
b.AddCustomAttributes(
    Extensions.GetMemberName&lt;ColumnSeries&gt;(x =&gt; x.IndependentAxis),
    <span class="kwrd">new</span> TypeConverterAttribute(<span class="kwrd">typeof</span>(ExpandableObjectConverter)));</pre>
</div>
<p>Blend displays a New button next to this property in Properties Panel; when clicked, it pops up the Select Object dialog, filtered with the property’s type IRangeAxis:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/04/image5.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ExpandableObjectConverter" src="http://www.ningzhang.org/wp-content/uploads/2009/04/image-thumb5.png" border="0" alt="ExpandableObjectConverter" width="644" height="399" /></a></p>
<p> </p>
<h3>Conclusion</h3>
<p>Blend and Silverlight together allow designers to create amazing UI against real controls directly, so it is very important that control developers take designer experience as part of overall control design and implementation. Having a custom property editor that provides nice editing UI and generates correct XAML is an important part of the designer experience. Hopefully this post helps you understand how to create custom property editors. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/04/03/property-value-editors-for-silverlight-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Write Silverlight Design Time for All Designers: Visual Studio 2008, Blend 2; Blend 3, and Visual Studio 2010</title>
		<link>http://www.ningzhang.org/2009/03/31/how-to-write-silverlight-design-time-for-all-designers-visual-studio-2008-blend-2-blend-3-and-visual-studio-2010/</link>
		<comments>http://www.ningzhang.org/2009/03/31/how-to-write-silverlight-design-time-for-all-designers-visual-studio-2008-blend-2-blend-3-and-visual-studio-2010/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:41:18 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/?p=284</guid>
		<description><![CDATA[This is part of the series on design time feature implementation in Silverlight. This post focuses on the breaking changes in designer extensibility framework introduced in Silverlight 3/Blend 3/Visual Studio 2010, and how to develop Silverlight design time to support all designers: Visual Studio 2008/Blend 2, and Visual Studio 2010/Blend 3.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>This is part of the series on design time implementation changes in <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>. This post focuses on the breaking changes in designer extensibility framework introduced in Silverlight 3/Blend 3/Visual Studio 2010, and how to develop Silverlight design time to support all designers: Visual Studio 2008/Blend 2, and Visual Studio 2010/Blend 3.</p>
<h3>Silverlight 2 Design Time for Visual Studio 2008 and Blend 2</h3>
<p>Visual Studio and Blend share the same designer extensibility framework, and use it for both WPF and Silverlight. <a href="http://msdn.microsoft.com/en-us/library/bb546938.aspx" target="_blank">WPF Designer Extensibility</a> on MSDN is probably the best reference available for the designer extensibility framework. The <a href="http://www.codeplex.com/Silverlight/Release/ProjectReleases.aspx?ReleaseId=19172" target="_blank">December 2008 Release</a> of <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> is based on Silverlight 2 (aka SL2), and has designer support for Visual Studio 2008 (aka VS9) and Blend 2. It is a good real world example in demonstrating how to develop Silverlight 2 design time features for VS9 and Blend 2. My blog post <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> explains in detail how it is done, and the implementation framework readers can use in their own design time implementation.</p>
<p>To recap, the Silverlight 2 design time framework for Visual Studio 2008 and Blend 2 in a nutshell:</p>
<ul>
<li>MWD: the design time extensibility framework is exposed through a set of assemblies, most notably Microsoft.Windows.Design.dll, Microsoft.Windows.Design.Extensibility.dll, and Microsoft.Windows.Design.Interaction.dll. Collectively those assemblies are called MWD. They are installed under %DevEnvDir%\PublicAssemblies (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies in 32bit OS, or&#160; C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies in 64bit OS). They are also GAC-ed. Most design time projects need to reference those MWD dlls. Visual Studio 2008 and Blend 2 use MWD version 3.5. <a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image34.png" target="_blank">       <br /><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="MWD in GAC" border="0" alt="MWD in GAC" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb31.png" width="580" height="226" /></a> </li>
<li>Naming Convention: Visual Studio and Blend load design time assemblies using a naming convention: for control assembly Foo.dll, VS and Blend will find its design time assemblies with the name Foo.Design.dll, Foo.VisualStudio.Design.dll, and Foo.Expression.Design.dll, in the same directory where Foo.dll is, or the Design sub directory. Visual Studio will load Foo.Design.dll and Foo.VisualStudio.Design.dll, while Blend will load Foo.Design.dll and Foo.Expression.Design.dll. So it is advised to put design time features shared across all designers in .Design.dll, and put Visual Studio and Blend specific design time features in .VisualStudio.Design.dll and .Expression.Design.dll respectively. </li>
<li>Entry Point: when Visual Studio or Blend loads a design time assembly, it uses reflection to find all classes that implement <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.iregistermetadata.aspx" target="_blank">IRegisterMetadata</a>, and calls its only method <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.iregistermetadata.register.aspx" target="_blank">Register</a>. <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=19172" target="_blank">Silverlight Toolkit December 2008 Release</a> has a design time implementation framework detailed in previous blog post <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a>. </li>
</ul>
<p>Below screenshots of Silverlight.Controls.Design.sln in Silverlight 2 Toolkit source in <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a> demonstrates implementation of SL2 design time for VS9 and Blend 2 discussed above:     <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image35.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SL2 design projects" border="0" alt="SL2 design projects" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb32.png" width="644" height="460" /></a></p>
<h3>What Changed In Silverlight 3, Blend 3 and Visual Studio 2010</h3>
<p>As stated in <a href="http://msdn.microsoft.com/en-us/library/bb514646.aspx" target="_blank">WPF Designer Extensibility Architecture</a> on MSDN:</p>
<blockquote><p>The WPF Designer supports the full extensibility framework. Expression Blend supports only property editors, metadata loading, and licensing. Blend does not support menu actions and adorners.</p>
</blockquote>
<p>Blend 2 has above limited support for Silverlight design time too, but Visual Studio 2008 has little support for Silverlight design time (just icons, metadata loading for few attributes like ToolboxBrowsableAttribute): it is more a viewer than a designer. To have WPF parity for Silverlight design time support, Blend 3 and Visual Studio 2010 (aka VS10) have to introduce breaking changes to the designer extensibility framework (i.e. MWD), most notably:</p>
<ul>
<li>MWD: most of the designer extensibility framework API stay the same, but their physical packaging changes: Microsoft.Windows.Design.dll is gone, and the version of all MWD assemblies changes from 3.5 to 4.0. Before Visual Studio 2010 Beta1, the only way to get the new MWD is via Blend 3 Preview, and its version is 3.7 instead of 4.0 for now:      <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image36.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="MWD in Blend 3" border="0" alt="MWD in Blend 3" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb33.png" width="493" height="393" /></a> </li>
<li>Entry Point: instead of reflect through <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.design.metadata.iregistermetadata.aspx" target="_blank">IRegisterMetadata</a> implementations, Blend 3 and Visual Studio 2010 use a new assembly attribute ProvideMetadataAttribute, and the metadataProviderType must implement IProvideAttributeTable:       <br /><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ProvideMetadataAttribute" border="0" alt="ProvideMetadataAttribute" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb34.png" width="580" height="376" /> </li>
<li>Naming Convention: because of the breaking changes like MWD version and entry point, existing design time assemblies developed against 3.5 MWD will not load in Blend 3 and Visual Studio 2010, you have to write new design time against the new 4.0 MWD for Blend 3 and Visual Studio 2010. While this is OK for Blend (since you can only use Blend 3 with Silverlight 3 and Blend 2 with Silverlight 2), this creates a challenge for Visual Studio, since you can use Visual Studio 2008 for Silverlight 3 development, as well as Visual Studio 2010 for Silverlight 2 development. </li>
</ul>
<p>Below table lists all supported scenarios and which version of MWD is used to load design time assemblies:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="77"><strong>SL\Designer</strong></td>
<td width="64"><strong>VS9</strong></td>
<td width="64"><strong>VS10</strong></td>
<td width="65"><strong>Blend2</strong></td>
<td width="65"><strong>Blend3</strong></td>
</tr>
<tr>
<td><strong>SL2</strong></td>
<td>MWD3.5</td>
<td>MWD4.0</td>
<td>MWD3.5</td>
<td>&#160;</td>
</tr>
<tr>
<td><strong>SL3</strong></td>
<td>MWD3.5</td>
<td>MWD4.0</td>
<td>&#160;</td>
<td>MWD4.0</td>
</tr>
</tbody>
</table>
<p>We can’t build one design time assembly against two incompatible MWDs, so we have to create two separate design time assemblies, one against each MWD. Design time assemblies are loaded by name, and we can’t have two assemblies with the same name in the same location, so the design time assembly loading mechanism (i.e., the naming convention) has to change, to allow multiple versions of the same design time assembly coexist.</p>
<p>While waiting for the new naming convention to come out with Blend 3 and Visual Studio 2010 RTM, we can do something clever now to support both VS9 and VS10. Remember current naming convention allows Visual Studio and Blend each to load two design assemblies:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="182"><strong>DLL\Designer</strong></td>
<td width="104"><strong>Visual Studio</strong></td>
<td width="59"><strong>Blend</strong></td>
</tr>
<tr>
<td>Foo.Design.dll</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td>Foo.VisualStudio.Design.dll</td>
<td>X</td>
<td>&#160;</td>
</tr>
<tr>
<td>Foo.Expression.Design.dll</td>
<td>&#160;</td>
<td>X</td>
</tr>
</tbody>
</table>
<p>so we can build the two assemblies against different versions of MWD:</p>
<ul>
<li>For Silverlight 3, we can have the shared .Design.dll build against MWD 4.0, so it can be loaded by both VS10 and Blend 3. We then have .VisualStudio.Design.dll build against MWD 3.5 and duplicate everything from shared .Design.dll, so it can be loaded by VS9. There is one minor issue though: we don’t have a place to put Visual Studio specific design time features for VS10, like using ToolboxBrowsableAttribute(false) to hide some controls from the increasingly crowded Visual Studio toolbox, since VS10 can’t load the .VisualStudio.Design.dll build against MWD 3.5. This will be solved with the new naming convention once Visual Studio 2010 RTM. </li>
</ul>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="182"><strong>DLL\MWD\Designer</strong></td>
<td width="59"><strong>MWD</strong></td>
<td width="46"><strong>VS9</strong></td>
<td width="53"><strong>VS10</strong></td>
<td width="66"><strong>Blend3</strong></td>
</tr>
<tr>
<td><strong>Foo.Design.dll</strong></td>
<td>4.0</td>
<td>&#160;</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td><strong>Foo.VisualStudio.Design.dll</strong></td>
<td>3.5</td>
<td><strong>X</strong></td>
<td><strong>?</strong></td>
<td>&#160;</td>
</tr>
<tr>
<td><strong>Foo.Expression.Design.dll</strong></td>
<td>4.0</td>
<td>&#160;</td>
<td>&#160;</td>
<td>X</td>
</tr>
</tbody>
</table>
<ul>
<li>For Silverlight 2, follow the same approach: have the shared .Design.dll build against MWD 4.0, but have both .VisualStudio.Design.dll and .Expression.Design.dll build against MWD 3.5 and duplicate everything in shared .Design.dll. This way, both VS9 and Blend 2 will work just fine, but with the&#160; same issue that there is no place to put Visual Studio specific features for VS10. Again, that will be solved with the new naming convention in VS10. </li>
</ul>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="182"><strong>DLL\MWD\Designer</strong></td>
<td width="64"><strong>MWD</strong></td>
<td width="64"><strong>VS9</strong></td>
<td width="64"><strong>VS10</strong></td>
<td width="64"><strong>Blend2</strong></td>
</tr>
<tr>
<td><strong>Foo.Design.dll</strong></td>
<td>4.0</td>
<td>&#160;</td>
<td>X</td>
<td>X</td>
</tr>
<tr>
<td><strong>Foo.VisualStudio.Design.dll</strong></td>
<td>3.5</td>
<td><strong>X</strong></td>
<td><strong>?</strong></td>
<td>&#160;</td>
</tr>
<tr>
<td><strong>Foo.Expression.Design.dll</strong></td>
<td>3.5</td>
<td>&#160;</td>
<td>&#160;</td>
<td>X</td>
</tr>
</tbody>
</table>
<p> <br />
<h3>Design Time Feature Implementation in Silverlight 3 Toolkit</h3>
<h4>MWD</h4>
<p>The design projects in Silverlight 3 Toolkit in <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a> followed above mentioned scheme to support both Visual Studio 2008 and Visual Studio 2010, as well as Blend 3.</p>
<p>Download the <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a>, unzip the source code, load Silverlight.Controls.Design.sln into Visual Studio 2008. Use the simpler Control.Input.Design project as example:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image37.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Controls.Input.Design.csproj in Silverlight 3 Toolkit Source" border="0" alt="Controls.Input.Design.csproj in Silverlight 3 Toolkit Source" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb35.png" width="644" height="454" /></a></p>
<ul>
<li>Design projects for VS9/Blend3 need to reference the new 4.0 MWD. Here we use pre-build event to invoke CopySystemWindows.bat to locate Blend 3 and copy the two&#160; MWD dlls to Binaries directory. </li>
<li>Please note the minor changes to CopySystemWindows.bat file: we need to quote “%THIS_DIR%\Binaries\Blend3” (lines in yellow) to handle cases where there is a space in the path to the directory the source code is unzipped to. </li>
</ul>
<p>If you don’t like the fragile CopySystemWindows.bat file or using build events, you can set Reference Paths to help Visual Studio find where the new MWD is, as shown below. The only caveat is that you need specify both %programfiles% and %programfiles(x86)% to make it build on both x86 and x64 machines.</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image38.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Controls.Input.Design.csproj in Silverlight 3 Toolkit Source" border="0" alt="Controls.Input.Design.csproj in Silverlight 3 Toolkit Source" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb36.png" width="644" height="457" /></a></p>
<p>The reference paths setting is persisted into the .csproj.user file:</p>
<blockquote><p>&lt;Project xmlns=&quot;<a href="http://schemas.microsoft.com/developer/msbuild/2003&quot;">http://schemas.microsoft.com/developer/msbuild/2003&quot;</a>&gt;       <br />&#160; &lt;PropertyGroup&gt;       <br />&#160;&#160;&#160; &lt;ReferencePath&gt;c:\Program Files\Microsoft Expression\Blend 3 Preview\;c:\Program Files (x86)\Microsoft Expression\Blend 3 Preview\&lt;/ReferencePath&gt;       <br />&#160; &lt;/PropertyGroup&gt;       <br />&lt;/Project&gt;</p>
</blockquote>
<h4>Metadata.cs</h4>
<p>I use the same implementation framework as described in <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a>, with some minor changes:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image39.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Metadata.cs in Silverlight 3 Toolkit Source" border="0" alt="Metadata.cs in Silverlight 3 Toolkit Source" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb37.png" width="644" height="482" /></a></p>
<ul>
<li>I moved links to shared files Extensions.cs and MetadataBase.cs from Controls.Design.Common folder to under a solution folder with the same name; </li>
<li>Metadata.cs in .Design and .Expression.Design projects use the new entry point: use ProvideMetadata assembly attribute, and implement IProvideAttributeTable interface; </li>
<li>add note that everything in AddAttributes() method needs to be duplicated in corresponding .VisualStudio.Design project. </li>
</ul>
<p>The .VisualStudio.Design projects still use the old IRegisterMetadata interface in MWD 3.5, but:    <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image40.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb38.png" width="644" height="482" /></a></p>
<ul>
<li>under Controls.Design folder are links to all *Metadata.cs files in corresponding .Design project; </li>
<li>AddAttributes() method duplicates the content of AddAttributes() method in corresponding .Design project. </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image41.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Controls.Input.Expression.Design.csproj in Silverlight 3 Toolkit Source" border="0" alt="Controls.Input.Expression.Design.csproj in Silverlight 3 Toolkit Source" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb39.png" width="644" height="482" /></a></p>
<h3>Conclusion</h3>
<p>While the breaking changes in MWD may cause some inconvenience, it is necessary to implement as rich a design time experience for Silverlight as for WPF. This post describes a way to handle the breaking changes and still support all existing designers: Visual Studio 2008, Blend 2, and Blend 3. Once Visual Studio 2010 is publicly available, I will blog about the new naming convention, and how Toolkit design time work in Visual Studio 2010. Stay tuned!   </p>
<h3>12/5/2009: Update for VS2010 Beta2</h3>
<p>To solve above problem of supporting both Visual Studio 2008/Blend2 and Visual Studio 2010/Blend3, which use incompatible versions of MWDs (v3.5 vs.. v4.0), the naming convention for design time assemblies is enhanced from VS2010 Beta2 and Blend 3: </p>
<p><em>for a runtime assembly Foo.dll, the shared design time assembly is named Foo.Design*.dll, the Visual Studio specific design time assembly is named Foo.VisualStudio.Design*.dll, and the Blend specific design time assembly is named Foo.Expression.Design*.dll, where * can be zero or more valid characters for file names. When a designer (like Visual Studio or Blend) tries to load a design time assembly and several fit the naming convention, zero or one will be loaded:</em></p>
<ul>
<li><em>If the MWD version referenced by the design-time assembly has a different major version number than the designer’s MWD version, then the design-time assembly will not load and is bypassed.</em> </li>
<li><em>If more than one design-time assembly is compatible with the designer’s MWD version, the Designer loads the one compiled against the highest MWD version that is less than or equal to the designer’s MWD version.</em> </li>
</ul>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=1ea49236-0de7-41b1-81c8-a126ff39975b&amp;displaylang=en">Silverlight 3 SDK GDR 2</a> (also installed by VS2010 automatically) and <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430#DownloadId=62369" target="_blank"></a><a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30514" target="_blank">Silverlight 3 Toolkit October 2009 Release</a> use the new naming convention to support both VS2008 and VS2010. Take System.Windows.Controls.dll for example, System.Windows.Controls.VisualStudio.Design.dll is built against MWD 3.5 and is used by VS2008, which uses the old naming convention; a new System.Windows.Controls.Toolkit.VisualStudio.Design.4.0.dll built against MWD 4.0 is added for VS2010, which understands the new naming convention.&#160; Please see <a href="http://www.ningzhang.org/2009/11/30/silverlight-design-time-assemblies/" target="_blank">Silverlight Design Time Assemblies</a> for more information. </p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ad974a0f-cd41-40a4-a7fc-40c0274b3640" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Design+Time" rel="tag">Design Time</a>,<a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a>,<a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/Visual+Studio" rel="tag">Visual Studio</a>,<a href="http://technorati.com/tags/Blend" rel="tag">Blend</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/03/31/how-to-write-silverlight-design-time-for-all-designers-visual-studio-2008-blend-2-blend-3-and-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight Toolkit Design Time Features: March 2009 Release Update</title>
		<link>http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/</link>
		<comments>http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 05:44:24 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Silverlight SDK]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/?p=234</guid>
		<description><![CDATA[This post details how to install and develop with Silverlight Toolkit, on both Silverlight 2 and Silverlight 3, with Visual Studio 2008, Blend 2, and blend 3. It showcases the great design time support in Silverlight Toolkit, like setup, registering with Visual Studio and Blend, leveraging new extensibility support like DefaultInitializer, AlternateContentPropertyAttribute, and PropertyValueEditor.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>The <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">March 2009 Release</a> of <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> has lots of new features and improvements. Among them, updates for design time features:</p>
<ul>
<li>a new msi based installer that provides tight integration with Visual Studio and Blend out of box, thus making Silverlight development with the Toolkit much easier; </li>
<li>support both Silverlight 2 development with Visual Studio 2008 and Blend 2, and Silverlight 3 development with Visual Studio 2008 and Blend 3; </li>
<li>add design time features for the six new controls (<a href="http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201&amp;ANCHOR#Accordion">Accordion</a>, <a href="http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201&amp;ANCHOR#DomainUpDown">DomainUpDown</a>, <a href="http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201&amp;ANCHOR#LayoutTransformer">LayoutTransformer</a>, <a href="http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201&amp;ANCHOR#TimePicker">TimePicker</a>, <a href="http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201&amp;ANCHOR#TimeUpDown">TimeUpDown</a>, <a href="http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%201&amp;ANCHOR#TransitioningContentControl">TransitioningContentControl</a>); </li>
<li>leverage the new design time extensibility framework in Blend 3 (and soon in Visual Studio 2010) and improve design time features for existing controls, like default intializers, AlternateContentPropertyAttribute, and custom editors, to provide a much better design experience, especially in Blend 3. </li>
</ul>
<p>This post is an update for my prior post <a href="http://www.ningzhang.org/2008/12/13/design-time-features-in-silverlight-toolkit/" target="_blank">Design Time Features in Silverlight Toolkit</a>.</p>
<h3>Silverlight 2 Development with Visual Studio 2008 and Blend 2</h3>
<h4>Setup</h4>
<ul>
<li>First, follow step 1 and 2 on <a href="http://silverlight.net/GetStarted" target="_blank">http://silverlight.net/GetStarted</a> to install Silverlight 2 and Blend 2: </li>
</ul>
<p><a href="http://silverlight.net/GetStarted" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="http://silverlight.net/GetStarted/" border="0" alt="http://silverlight.net/GetStarted/" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image.png" width="572" height="484" /></a></p>
<ul>
<li>Then follow step 4 to <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> CodePlex page, click “Download the latest release” link: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="http://www.codeplex.com/Silverlight" border="0" alt="http://www.codeplex.com/Silverlight" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb.png" width="572" height="484" /></a></p>
<ul>
<li>Click the “Silverlight 2 Toolkit March 2009 Installer” link, and run the msi: (You can also save the msi to your computer and run it later) </li>
</ul>
<p><a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" border="0" alt="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image2.png" width="644" height="409" /></a></p>
<p>After the installer finishes, you will see Silverlight 2 Toolkit installed on your computer:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image3.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="C:Program FilesMicrosoft SDKsSilverlightv2.0ToolkitMarch 2009LibrariesDesign" border="0" alt="C:Program FilesMicrosoft SDKsSilverlightv2.0ToolkitMarch 2009LibrariesDesign" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb1.png" width="618" height="484" /></a></p>
<p>Please note:</p>
<ul>
<li>there is a namespace (both CLR and xmlns prefix) and assembly name change from Microsoft.Windows.Controls in previous releases to System.Windows.Controls in this release. Please see <a href="http://blogs.msdn.com/sburke/" target="_blank">Shawn Burke</a>’s post <a href="http://blogs.msdn.com/sburke/archive/2009/03/20/silverlight-toolkit-march-2009-release.aspx" target="_blank">Silverlight Toolkit March 2009 Release</a> for a good explanation for the change and its implications for development with Silverlight Toolkit. </li>
<li>besides the existing four toolkit assemblies (Controls, Controls.Input, Control.DataVisualization, and Controls.Theming) in previous releases, there is a new assembly added in this release: Controls.Layout, which contained Accordion, LayoutTransfer, and TransitioningContentControls.</li>
<li>we still follow the same convention for design time assemblies: there are three design time assemblies for each run time assembly (.design, .expression.design, and .visualstudio.design), and all design time assemblies reside in the Design subfolder.</li>
</ul>
<p>There is also a new Microsoft Silverlight 2 Toolkit March 2009 Start Menu item group to provide easy access to all Toolkit related information, like docs, samples, source code on local computer, and Silverlight Toolkit forums and CodePlex page on web:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image4.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Microsoft Silverlight 2 Toolkit March 2009 Start Menu item" border="0" alt="Microsoft Silverlight 2 Toolkit March 2009 Start Menu item" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb2.png" width="416" height="776" /></a></p>
<h4>Walkthrough</h4>
<p>Let’s use a walkthrough on how to create a Chart control in Blend to demonstrate the design time features for Silverlight Toolkit:</p>
<ul>
<li>Create a new Silverlight 2 Application project in Blend: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image5.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="New Project Dialog" border="0" alt="New Project Dialog" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb3.png" width="502" height="327" /></a></p>
<ul>
<li>Add reference to the Toolkit assemblies: (Here I add all Toolkit assemblies, but only System.Windows.Controls.DataVisualization.Toolkit.dll is needed for this walkthrough) </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image6.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Add Reference to Toolkit Assemblies" border="0" alt="Add Reference to Toolkit Assemblies" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb4.png" width="644" height="412" /></a></p>
<ul>
<li>open Asset Library, click Custom Controls tab, and double click the Chart control: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image7.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Toolkit Controls in Asset Library" border="0" alt="Toolkit Controls in Asset Library" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb5.png" width="644" height="412" /></a></p>
<ul>
<li>Add a Chart control to the design surface, set its Title property under Data Visualization category in Properties Panel: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image8.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Infotip, custom category, and custom editor" border="0" alt="Infotip, custom category, and custom editor" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb6.png" width="644" height="412" /></a></p>
<ul>
<li>Click the New button next to DataContext property under Common Properties, select PointCollection from the Select Object dialog, and then click OK: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image9.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create DataContext" border="0" alt="Create DataContext" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb7.png" width="644" height="411" /></a></p>
<ul>
<li>In XAML editor, replace the generated XAML “&lt;PointCollection /&gt;” to be like those highlighted in below screenshot, to provide some data for the Chart control to display: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image10.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Edit DataContext" border="0" alt="Edit DataContext" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb8.png" width="644" height="412" /></a></p>
<ul>
<li>Click the … button next to “Series (Collection)” property under Common Properties category, click “Add another item” button in the Series Collection Editor dialog, select ColumnSeries in Select Object dialog, and then click OK: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image11.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create Series" border="0" alt="Create Series" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb9.png" width="644" height="411" /></a></p>
<ul>
<li>Back to the Series Collection Editor dialog, set properties for the newly created ColumnSeries in the right Properties pane:
<ul>
<li>Set DependeptValuePath to X and IndependentValuePath to Y, both in Common Properties category <a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image12.png" target="_blank">           <br /><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Series Collection Editor" border="0" alt="Series Collection Editor" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb10.png" width="484" height="484" /></a> </li>
<li>Click the rectangle to the right of ItemsSource property, select Data Binding… from the popped up context menu:         <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image13.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Databinding for ItemsSource" border="0" alt="Databinding for ItemsSource" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb11.png" width="483" height="484" /></a> </li>
<li>Select the only item, PointCollection (Array) item, in Fields listbox in the Create Data Binding dialog, then click the Finish button: <a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image14.png" target="_blank">           <br /><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Create Data Binding Dialog" border="0" alt="Create Data Binding Dialog" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb12.png" width="512" height="484" /></a> </li>
<li>Back to the Series Collection Editor dialog again, notice the ItemsSource property is now surrounded with a yellow rectangle, indicating it now has a changed data binding value. Click OK to close the Series Collection Editor dialog: <a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image15.png" target="_blank">           <br /><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Series Collection Editor" border="0" alt="Series Collection Editor" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb13.png" width="484" height="484" /></a> </li>
</ul>
</li>
</ul>
<ul>
<li>We are back to Blend main window, and voila, we have a Chart control rendered nicely in the design view: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image16.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Yes!" border="0" alt="Yes!" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb14.png" width="644" height="412" /></a></p>
<p>We can hit F5 to build and run the project from Blend, or open the project in Visual Studio to continue editing the xaml and code. Notice in below screenshot that the Visual Studio toolbox is auto populated with Toolkit controls:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image17.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio" border="0" alt="Visual Studio" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb15.png" width="644" height="454" /></a></p>
<h3>Silverlight 3 Development with Visual Studio 2008 and Blend 3</h3>
<h4>Setup</h4>
<p><u>Before you start, please read the Important developer notes on </u><a title="http://silverlight.net/getstarted/silverlight3/default.aspx#tools" href="http://silverlight.net/getstarted/silverlight3/default.aspx#tools"><u>http://silverlight.net/getstarted/silverlight3/default.aspx#tools</u></a><u> carefully (in below screenshot too)</u>.</p>
<ul>
<li>First, follow the first three steps on <a title="http://silverlight.net/getstarted/silverlight3/default.aspx#tools" href="http://silverlight.net/getstarted/silverlight3/default.aspx#tools">http://silverlight.net/getstarted/silverlight3/default.aspx#tools</a> page to install Silverlight 3 Beta Tools, SDK (some of previous Toolkit controls, like DockPanel, WrapPanel, Expander, Viewbox, HeaderedContentControl, HeaderedItemsControl, TreeView, AutoCompleteBox etc, and their design time assemblies, have moved to SDK in Silverlight 3), and Blend 3 Preview:<a href="http://silverlight.net/getstarted/silverlight3/default.aspx#tools" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="http://silverlight.net/getstarted/silverlight3/default.aspx#tools" border="0" alt="http://silverlight.net/getstarted/silverlight3/default.aspx#tools" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image18.png" width="644" height="449" /></a> </li>
<li>Then, follow the fourth step to <a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit CodePlex Project site</a>, click <a href="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" target="_blank">Download the latest release</a> link, then click and run the Silverlight 3 Toolkit March 2009 Installer:<a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image19.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" border="0" alt="http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20430" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb16.png" width="644" height="449" /></a> </li>
</ul>
<p>After the installer finishes, you will see Silverlight 3 Beta SDK and Toolkit installed on your computer:</p>
<ul>
<li>SDK: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image20.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Silverlight 3 SDK: C:Program FilesMicrosoft SDKsSilverlightv3.0LibrariesClientDesign" border="0" alt="Silverlight 3 SDK: C:Program FilesMicrosoft SDKsSilverlightv3.0LibrariesClientDesign" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb17.png" width="644" height="313" /></a></p>
<ul>
<li>Toolkit: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image21.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Silverlight 3 Toolkit: C:Program FilesMicrosoft SDKsSilverlightv3.0ToolkitMarch 2009Libraries" border="0" alt="Silverlight 3 Toolkit: C:Program FilesMicrosoft SDKsSilverlightv3.0ToolkitMarch 2009Libraries" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb18.png" width="644" height="313" /></a></p>
<p>And the Microsoft Silverlight 3 Toolkit March 2009 start menu item group for easy access to all Toolkit information:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image22.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb19.png" width="407" height="529" /></a></p>
<h4>Walkthrough</h4>
<p>Now let’s do the same create a Chart control walkthrough, but this time with Blend 3:</p>
<ul>
<li>Start Microsoft Expression Blend 3 Preview from Start menu, create a new Silverlight 3 Application + Website project: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image23.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blend 3 New Project Dialog" border="0" alt="Blend 3 New Project Dialog" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb20.png" width="398" height="451" /></a></p>
<ul>
<li>Click the Asset Library, notice the Controls tab is pre-populated with Silverlight 3 runtime and SDK controls, including those used to be in Toolkit, like DockPanel, Expander, TreeView etc. Blend 3 populates Asset Library asynchronously, so you may notice a few seconds delay before the Controls tab is fully populated. </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image24.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Asset Library, Controls Tab" border="0" alt="Asset Library, Controls Tab" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb21.png" width="644" height="377" /></a></p>
<ul>
<li>Click the Custom Controls tab, notice it is pre-populated with Toolkit controls: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image25.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Asset Library, Custom Controls tab" border="0" alt="Asset Library, Custom Controls tab" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb22.png" width="644" height="377" /></a></p>
<ul>
<li>Double click the Chart control, click and drag on the design surface, and voila, a Chart controls is created, initialized with some sample data, and nicely rendered. We had to go through a lot manual steps in Blend 2 to create the same result: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image26.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart Default Initializer" border="0" alt="Chart Default Initializer" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb23.png" width="644" height="377" /></a></p>
<p>Please note in above screenshot:</p>
<ul>
<li>in the projects panel on the right, reference to System.Windows.Controls.DavaVisualization.Toolkit.dll is automatically added;</li>
<li>in the xaml editor, the xmlns:chartingToolkit definition is automatically added</li>
<li>also notice a few Blend 3 new features, like custom icon for Chart control (in both Object and Timeline pane and Properties pane), default initializer that generates the initial xaml for the Chart control.</li>
</ul>
<p>Since the Chart control is so easily created, let’s do a bit more in Blend 3 walkthrough.</p>
<ul>
<li>Click Properties Tab on the right, and expand the Chart control in Objects and Timeline pane on the left: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image27.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart: AlternateContentPropertyAttribute" border="0" alt="Chart: AlternateContentPropertyAttribute" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb24.png" width="644" height="377" /></a>Please note in above screenshot:</p>
<ul>
<li>In Properties Panel, the little white dots to the right highlight the properties initialized by Chart control’s default initializer; </li>
<li>In Objects and Timeline Panel, there are LegendItems and Axes properties under Chart object, and IndependentAxis and DependentRangeAxis properties under ColumnSeries object. Those are called alternate content properties. Displaying them in the object hierarchy allows easy access to those properties at design time. For example, we can drag and drop a LinearAxis to the Axes property: </li>
</ul>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image28.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AlternateContentProperty" border="0" alt="AlternateContentProperty" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb25.png" width="644" height="377" /></a></p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image29.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="AlternateContentProperty" border="0" alt="AlternateContentProperty" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb26.png" width="644" height="377" /></a></p>
<p>So comparing the same create a Chart control walkthrough in Blend 3 and Blend 2, we can see that Blend 3 a much better designer, and our design time assemblies for Blend 3 have leveraged many of the new design time extensibility capabilities, like default initializer and alternate content property, to greatly improve the design experience for Toolkit controls.</p>
<p>Now open the project in Visual Studio:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image30.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Design Experience" border="0" alt="Visual Studio Design Experience" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb27.png" width="644" height="394" /></a></p>
<p>Please notice that:</p>
<ul>
<li>The toolbox on the left is pre-populated with SDK and Toolkit controls. </li>
<li>The output windows at bottom right displays an error message about failed to load design assembly. Ignore it safely. </li>
</ul>
<h3>Design Experience in Visual Studio 2008 (Both Silverlight 2 and 3)</h3>
<p>Toolkit design experience in Visual Studio is pretty much the same for both Silverlight 2 and Silverlight 3, so we can continue the following from either of above the two walkthroughs. For convenience sake, we will continue from the Silverlight 3 walkthrough immediately above.</p>
<p>Now drag and drop the Accordion control from toolbox to the XAML editor:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image31.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Design Experience" border="0" alt="Visual Studio Design Experience" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb28.png" width="644" height="394" /></a></p>
<p>We can see that:</p>
<ul>
<li>In XAML editor
<ul>
<li>xmlns:layoutToolkit=&quot;clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit&quot;&#160; is automatically added </li>
<li>&lt;layoutToolkit:Accordion&gt;&lt;/layoutToolkit:Accordion&gt; is automatically added </li>
</ul>
</li>
<li>In Solution Explorer
<ul>
<li>references to System.Windows.Controls.Layout.Toolkit assembly, and the two assemblies it depends on, System.windows.Controls.Toolkit in Toolkit and System.Windows.Controls in SDK, are added automatically to the project </li>
</ul>
</li>
</ul>
<p>Now drag and drop a few controls from toolbox to XAML editor.</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image32.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Design Experience" border="0" alt="Visual Studio Design Experience" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb29.png" width="644" height="394" /></a></p>
<p>Please notice in above screenshot that:</p>
<ul>
<li>in XAML editor
<ul>
<li>we can see that we dragged and dropped Calendar, AutoCompleteBox and NumericUpdown to the Accordion </li>
<li>appropriate xmlns definitions and xaml code are added automatically </li>
</ul>
</li>
<li>In the Preview window
<ul>
<li>XAML code is properly rendered as we edit in XAML editor </li>
</ul>
</li>
<li>In Code editor
<ul>
<li>notice the intellisense and infotip </li>
<li>Safely ignore the errors in Errors Window as we type in XAML or code editors before we finish the statement </li>
</ul>
</li>
<li>In Solution Explorer:
<ul>
<li>references to needed assemblies are automatically added </li>
</ul>
</li>
</ul>
<p>Hit F5, and it builds and runs fine:</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/03/image33.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Visual Studio Design Experience" border="0" alt="Visual Studio Design Experience" src="http://www.ningzhang.org/wp-content/uploads/2009/03/image-thumb30.png" width="644" height="394" /></a></p>
<h3>Credits</h3>
<p>I certainly hope you are excited about the design experience improvements, since I implemented most of it <img src='http://www.ningzhang.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  <a href="http://www.jeff.wilcox.name/" target="_blank">Jeff Wilcox</a> implemented the installer, and <a href="http://silverlight.net/blogs/JustinAngel/" target="_blank">Justin Angel</a> wrote the spec for both the design time experience and installer. Many of my other colleagues contributed to the design experience too, especially <a href="http://www.sitechno.com/blog/" target="_blank">RJ Boeke</a>, <a href="http://themechanicalbride.blogspot.com/" target="_blank">Jafar Husain</a>, and <a href="http://blogs.msdn.com/delay/" target="_blank">David Anson</a>. Many thanks to the folks in Blend and Cider teams, particularly <a href="http://blogs.msdn.com/unnir/" target="_blank">Unni Ravindranathan</a>, Gary Linscott, Peter Blois; Brian Pepin, and Eric Fisk. Without them, none of the design experience improvements would be possible. And to <a href="http://blogs.msdn.com/sburke/" target="_blank">Shawn Burke</a>, for his support and emphasis on design time features, and deep involvement in solving key hard technical problems.</p>
<p>I will write a follow up post on design time implementation updates in March 2009 release. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/03/19/silverlight-toolkit-design-time-features-march-2009-release-update/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Add an Toolbox Icon for Your Silverlight Control</title>
		<link>http://www.ningzhang.org/2009/01/21/how-to-add-an-toolbox-icon-for-your-silverlight-control/</link>
		<comments>http://www.ningzhang.org/2009/01/21/how-to-add-an-toolbox-icon-for-your-silverlight-control/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 02:22:38 +0000</pubDate>
		<dc:creator>Ning Zhang</dc:creator>
				<category><![CDATA[Design Time]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Icon]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.ningzhang.org/?p=103</guid>
		<description><![CDATA[This post describes how to add Visual Studio toolbox icon and Blend Asset Library icon for Silverlight controls.]]></description>
			<content:encoded><![CDATA[<p>Change History:</p>
<ul>
<li>first published on 1/21/2008 for Silverlight 2/VS2008/Toolkit December 2008 Release. </li>
<li><a href="#update20091205">updated on 12/5/2009</a> for Silverlight 4/VS2010/Blend3/Toolkit November 2009 Release. </li>
</ul>
<p>Controls in Silverlight runtime (ex. system.windows.dll) and SDK (ex. system.windows.controls.dll) have nice toolbox icons in Visual Studio and Blend. December 2008 release of Silverlight Toolkit added that for Toolkit controls too, as described in my previous post <a href="http://www.ningzhang.org/2008/12/13/design-time-features-in-silverlight-toolkit/" target="_blank">Design Time Features in Silverlight Toolkit</a>:</p>
<p><a href="http://lh6.ggpht.com/_iM_rdx7nVGA/SUOfwJESd6I/AAAAAAAAAWM/N9ZKR7a6pDU/s1600-h/image%5B61%5D.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="custom icons" src="http://lh6.ggpht.com/_iM_rdx7nVGA/SUOf0JGaP4I/AAAAAAAAAWQ/KRd4VR1Uh4U/image_thumb%5B37%5D.png?imgmax=800" width="640" height="480" /></a></p>
<p>This post explains how it is done in Silverlight 2 SDK, and in December 2008 release of the Silverlight Toolkit. </p>
<h3>Control Icons in Run Time Assembly</h3>
<p>The December 2008 Release of Silverlight Toolkit demonstrated how to embed toolbox icons for controls without using a design time assembly.</p>
<p>Open Silverlight.Controls.sln in Visual Studio (see previous post <a href="http://www.ningzhang.org/2008/12/28/design-time-feature-implementation-in-silverlight-toolkit/" target="_blank">Design Time Feature Implementation in Silverlight Toolkit</a> for more information on how to download the toolkit source):     <br /><a href="http://www.ningzhang.org/wp-content/uploads/2009/01/image9.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Embed icons in run time assembly, visual studio view" src="http://www.ningzhang.org/wp-content/uploads/2009/01/image-thumb11.png" width="386" height="704" /></a></p>
<p>Or open Controls.csproj in notepad:</p>
<blockquote><p>&lt;ItemGroup&gt;      <br />&#160; &lt;EmbeddedResource Include=&quot;Microsoft.Windows.Controls.AutoCompleteBox.Icon.png&quot; /&gt;       <br />&#160; &lt;EmbeddedResource Include=&quot;Microsoft.Windows.Controls.DockPanel.Icon.png&quot; /&gt;       <br />&#160; &lt;EmbeddedResource Include=&quot;Microsoft.Windows.Controls.Expander.Icon.png&quot; /&gt;       <br />&#160; &lt;EmbeddedResource Include=&quot;Microsoft.Windows.Controls.Label.Icon.png&quot; /&gt;       <br />&#160; &lt;EmbeddedResource Include=&quot;Microsoft.Windows.Controls.TreeView.Icon.png&quot; /&gt;       <br />&#160; &lt;EmbeddedResource Include=&quot;Microsoft.Windows.Controls.Viewbox.Icon.png&quot; /&gt;       <br />&lt;/ItemGroup&gt;</p>
</blockquote>
<p>Or open Microsoft.Windows.Controls.dll in reflector:</p>
<p>&#160;<a href="http://www.ningzhang.org/wp-content/uploads/2009/01/image10.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Embed icons in run time assembly, reflector view" src="http://www.ningzhang.org/wp-content/uploads/2009/01/image-thumb12.png" width="580" height="454" /></a></p>
<p>All three show that the custom toolbox icons are embedded resources in the run time assembly Microsoft.Windows.Controls.dll, with a particular naming convention. Take above <font face="System">Microsoft.Windows.Controls.Microsoft.Windows.AutoCompleteBox.Icon.png</font> as an example:</p>
<ul>
<li>The first <font face="System">Microsoft.Windows.Controls </font>is the root namespace, specified in controls.csproj file with line: <font face="System">&lt;RootNamespace&gt;System.Windows.Controls&lt;/RootNamespace&gt;</font> </li>
<li>The next <font face="System">Microsoft.Windows.Controls.AutoCompleteBox </font>is the fully qualified name of AutoCompleteBox class, including namespace but not assembly. </li>
<li>The rest of the name, <font face="System">Icon.png</font>, specify the icon resource type, as will be explained more later. </li>
</ul>
<h3>Control Icons in Design Time Assembly</h3>
<p>The Silverlight 2 SDK demonstrated the approach of embedding control icons in design time assembly.</p>
<p>Open System.Windows.Controls.Design.dll in reflector (it is installed under %ProgramFiles%\Microsoft SDKs\Silverlight\v2.0\Libraries\Client):</p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/01/image11.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="embed icon in design time assembly, reflector view" src="http://www.ningzhang.org/wp-content/uploads/2009/01/image-thumb13.png" width="443" height="429" /></a></p>
<p>Take above <font face="System">Controls.Design.Icons.Calendar.bmp </font>as an example:</p>
<ul>
<li><font face="System">Controls.Design </font>is the root namespace, specified in its csproj file with line <font face="System">&lt;RootNamespace&gt;Controls.Design&lt;/RootNamespace&gt;</font> </li>
<li><font face="System">Icons</font> is the subfolder where the Calendar.bmp file is in source tree </li>
<li><font face="System">Calendar.bmp</font> is the name of the icon resource file in source tree </li>
</ul>
<h3>Control Icon Resource Naming Convention</h3>
<p>So from above two examples, we can see that custom toolbox icons for controls are embedded resources in either run time assembly (so you don&#8217;t need to ship a design time assembly), or design time assembly (so you have flexibility to change icons, like localize it for a different culture, without touching the run time assembly). The tools (Visual Studio 2008 SP1 for now) try to find the icons based on a special naming convention:</p>
<ol>
<li>Search for resources whose file name without extension matches the type name of the control, including the namespace, with a “[.icon*].{XAML | BMP| PNG | GIF | JPG | JPEG}” .
<ol>
<li>Note that subdirectories affect the namespace in which embedded resources are found. For example, the Toolkit icons are put under a Microsoft.Windows.Controls subfolder, to avoid putting this long string in all icon file names; while the SDK put all icons under a Icons subfolder. </li>
<li>Supported extensions and file types are: XAML, BMP, GIF, JPG, JPEG and PNG </li>
<li>Recommended image size for Bitmap based file formats is 64&#215;64. </li>
<li>The [.icon*] in the naming convention is optional and allows you to specify multiple sizes of the image that is used as the icon. The match follows the following algorithm:
<ol>
<li>Vector XAML </li>
<li>If there is an exact match on size (both dimensions) use it </li>
<li>Use the closest match based on size and aspect ratio </li>
</ol>
</li>
<li>If a given resource file is not valid XAML or a valid image file, the next match will be used until one is found. </li>
</ol>
</li>
<li>If an image is not found in the same namespace as the control, a loose match based on the type name alone will be searched for against all of the resources, as in the SDK case. </li>
<li>Different hosts use different image sizes for their toolbox icon.
<ol>
<li>Blend uses 24&#215;24 for their large size and 12&#215;12 for their small size (I don&#8217;t think this is working in Blend 2 SP1) . </li>
<li>Cider (Visual Studio) uses 16&#215;16 bmp files. </li>
</ol>
</li>
</ol>
<p>The blog post <a href="http://blogs.msdn.com/jnak/archive/2007/12/10/specifying-a-toolbox-icon-for-a-control-in-the-wpf-designer.aspx" target="_blank">Specifying a Toolbox Icon for a Control in WPF Designer</a> describes the naming convention in more details. </p>
<p></p>
<p> <a name="update20091205"><br />
<h3>Update for Blend3 &amp; VS2010</h3>
<p> </a>
<p>Since this post was first published on 1/21/2008, we’ve made two key improvements regarding control icons: </p>
<ul>
<li>Blend 3 shows icons for controls too: big icons (24&#215;24) in Asset Library, and small icons (12&#215;12) in Objects and Timeline.&#160; See <a href="http://www.ningzhang.org/2009/09/29/silverlight-design-time-toolkit-july-2009-release-update/" target="_blank">Silverlight Design Time: Toolkit July 2009 Release Update</a> for more information. </li>
<li>You can register your controls (and their associated icons) with Blend 3 and Visual Studio 2010. See <a href="http://www.ningzhang.org/2009/04/30/register-silverlight-controls-with-visual-studio-and-blend/" target="_blank">Register Silverlight Controls with Visual Studio and Blend</a> for more information. </li>
<li>The naming convention for icon resource is revised together with the naming convention for design time assemblies. See <a href="http://www.ningzhang.org/2009/11/30/silverlight-design-time-assemblies/" target="_blank">Silverlight Design Time Assemblies</a> for more information on the enhanced naming convention for design time assemblies. Please note that <strong>the search for icon resource is in reverse order of the loading order of design time metadata</strong>, i.e., Blend will search for embedded icon resource for a control with above icon resource naming convention in *.Expression.Design*.dll first; only if it fails will Blend search the shared *.Design*.dll second; and only if if fails again will it search the corresponding runtime dll for the embedded icon resource; and if all have failed, Blend will display the default icon for the control. Visual Studio 2010 does it in similar way, but searches *.VisualStudio.Design*.dll first. </li>
<li>Blend and Visual Studio now support more icon format, and will scale the icon if the desired sized resource (24&#215;24 and 12&#215;12 for Blend, and 16&#215;16 for VS) isn’t found. </li>
</ul>
<p><a href="http://www.codeplex.com/Silverlight" target="_blank">Silverlight Toolkit</a> use following naming conventions for embedding icon resources:</p>
<ul>
<li>use full names (namespace+type, ex. System.Windows.Controls.Calendar) instead of just type names (ex. Calendar) to avoid ambiguity. </li>
<li>put icons for Blend in shared .design.dll, and icons for Visual Studio toolbox in .VisualStudio.Design*.dlls. This way, VS2010 can display the right toolbox icon if one exists in .VisualStudio.Design*.dll; if not, VS2010 can load the icon for Blend, scale it to 16&#215;16, and display it in toolbox. </li>
<li>put icon resource in runtime dll only as last resort (ex, to avoid shipping a design time assembly with only icon resource). </li>
</ul>
<p>You can see the control icon resource naming convention in <a href="http://silverlight.codeplex.com/sourcecontrol/changeset/view/35261?projectName=Silverlight#779504" target="_blank">Silverlight Toolkit source code</a>: </p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/12/image.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Embed Blend Icons in Shared .Design.dll" border="0" alt="Embed Blend Icons in Shared .Design.dll" src="http://www.ningzhang.org/wp-content/uploads/2009/12/image_thumb.png" width="584" height="347" /></a> </p>
<p><a href="http://www.ningzhang.org/wp-content/uploads/2009/12/image1.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Embed Visual Studio Icons in .VisualStudio.Design*.dll" border="0" alt="Embed Visual Studio Icons in .VisualStudio.Design*.dll" src="http://www.ningzhang.org/wp-content/uploads/2009/12/image_thumb1.png" width="584" height="347" /></a> </p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0144f365-e62b-4a6b-a1f0-59e32e5acc78" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a>,<a href="http://technorati.com/tags/Design+Time" rel="tag">Design Time</a>,<a href="http://technorati.com/tags/Visual+Studio" rel="tag">Visual Studio</a>,<a href="http://technorati.com/tags/Blend" rel="tag">Blend</a>,<a href="http://technorati.com/tags/Icon" rel="tag">Icon</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.ningzhang.org/2009/01/21/how-to-add-an-toolbox-icon-for-your-silverlight-control/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

