<?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>Greg Does IT &#187; Silverlight</title>
	<atom:link href="http://gregdoesit.com/tag/silverlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://gregdoesit.com</link>
	<description>Do it to get it</description>
	<lastBuildDate>Tue, 22 Nov 2011 12:59:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Stock Data Visualization Using Silverlight</title>
		<link>http://gregdoesit.com/2011/01/stock-data-visualization-using-silverlight/</link>
		<comments>http://gregdoesit.com/2011/01/stock-data-visualization-using-silverlight/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 16:22:23 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Financial]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=734</guid>
		<description><![CDATA[I&#8217;ve written an article on CodeProject on visualizing live and historic stock data using Silverlight. In the article I&#8217;m presenting a pretty generic way of fetching, parsing and displaying the stock data. The structure of the article is as follows: Define data structures for storing and defining interfaces for fetching live and historical data. Implement [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written an <a href="http://www.codeproject.com/KB/silverlight/visualizingstockdata.aspx">article on CodeProject</a> on visualizing live and historic stock data using Silverlight. In the article I&#8217;m presenting a pretty generic way of fetching, parsing and displaying the stock data.</p>
<p>The structure of the article is as follows:</p>
<ul>
<li>Define data structures for storing and defining interfaces for fetching live and historical data.</li>
<li>Implement fetching stock data using <a href="http://finance.google.com">Google Finance</a></li>
<li>Visualize fetched stock data using <a href="http://visiblox.com">Visiblox Charts for Silverlight</a></li>
</ul>
<p>Read the full article and download the source code on Codeproject: <a href="http://www.codeproject.com/KB/silverlight/visualizingstockdata.aspx"> Visualizing Live and Historic Stock Data Using Silverlight</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2011/01/stock-data-visualization-using-silverlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>10 Things Developers Will Love About Silverlight</title>
		<link>http://gregdoesit.com/2010/12/10-things-developers-will-love-about-silverlight/</link>
		<comments>http://gregdoesit.com/2010/12/10-things-developers-will-love-about-silverlight/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 13:51:38 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=694</guid>
		<description><![CDATA[On the Silverlight Firestarter Scott Guthrie gave a preview of the new features being developed in Silverlight 5. I&#8217;ve written an article on the 10 most important new features Silverlight developers should be excited about. These are the following: Debug Data Binding Expressions by Using Breakpoints in XAML Animations Made Easy with Transitions Navigating Up [...]]]></description>
			<content:encoded><![CDATA[<p>On the Silverlight Firestarter Scott Guthrie gave a preview of the new features being developed in Silverlight 5. I&#8217;ve <a href="http://www.visiblox.com/blog/2010/12/10-things-developers-will-love-about-silverlight-5#more-1822">written an article on the 10 most important new features</a> Silverlight developers should be excited about. These are the following:</p>
<ol>
<li>Debug Data Binding Expressions by Using Breakpoints in XAML</li>
<li>Animations Made Easy with Transitions</li>
<li>Navigating Up the Visual Tree in Bindings using RelativeSource and Mode=FindAncestor</li>
<li>Binding View Events to the ViewModel Using Custom Markup Extensions</li>
<li>Changing Styles Runtime By Binding in Style Setters</li>
<li>Networking No Longer Happening on the UI Thread</li>
<li>Vector Based Printing</li>
<li>HTML Content and Additional Permissions Within Trusted Silverlight Application</li>
<li>3D API</li>
<li>Smaller Enhancements: Text Clarity and Performance Improvements</li>
</ol>
<p>You can read the full article with details on all of these features <a href="http://www.visiblox.com/blog/2010/12/10-things-developers-will-love-about-silverlight-5#more-1822">on my Visiblox blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/12/10-things-developers-will-love-about-silverlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manipulating Styles At Runtime in Silverlight</title>
		<link>http://gregdoesit.com/2010/11/manipulating-styles-at-runtime-in-silverlight/</link>
		<comments>http://gregdoesit.com/2010/11/manipulating-styles-at-runtime-in-silverlight/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 15:18:50 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=684</guid>
		<description><![CDATA[I&#8217;ve been writing a 4 part series on everything (I think) is worth knowing about styles in Silverlight. The previous parts were Silverlight Styles: an Introduction, Silverlight Styles: Advanced Topics and Silverlight Styles: Further Advanced Topics The final part of the series is ready and it covers the following topics: Modifying Styles Runtime: the IsSealed [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a 4 part series on everything (I think) is worth knowing about styles in Silverlight. The previous parts were <a href="http://gregdoesit.com/2010/07/styles-in-silverlight-an-introduction/">Silverlight Styles: an Introduction</a>, <a href="http://gregdoesit.com/2010/07/styles-in-silverlight-advanced-topics-part-1/">Silverlight Styles: Advanced Topics</a> and <a href="http://gregdoesit.com/2010/07/styles-in-silverlight-advanced-topics-part-1/">Silverlight Styles: Further Advanced Topics</a></p>
<p>The final part of the series is ready and it covers the following topics:</p>
<ul>
<li><a href="http://www.visiblox.com/blog/2010/11/styles-in-silverlight-manipulating-in-runtime#isSealedProperty">Modifying Styles Runtime: the IsSealed Property</a> &#8211; modifying the Setters of a Style can only be done if the IsSealed property is set to false and this property is set to true as soon as the style gets applied to an element in the visual tree.
</li>
<li><a href="http://www.visiblox.com/blog/2010/11/styles-in-silverlight-manipulating-in-runtime#CloningStyles">Cloning Styles</a> &#8211; because sealed Styles can&#8217;t be modified, one needs to clone them to be able to manipulate them. I&#8217;m providing example code on how cloning of a Style can be done.</li>
<li><a href="http://www.visiblox.com/blog/2010/11/styles-in-silverlight-manipulating-in-runtime#mergingUsingBasedOn">Merging styles runtime</a> &#8211; I&#8217;m showing two ways of merging existing styles programatically, both using the BasedOn property of Style as well as just copying Style setters.</li>
</ul>
<p>You can read the detailed article and download source code for examples <a href="http://www.visiblox.com/blog/2010/11/styles-in-silverlight-manipulating-in-runtime">on my Visiblox blog</a> &#8211; I hope you&#8217;ll find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/11/manipulating-styles-at-runtime-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started With WP7 Development: Learning the WP7 Ecosystem</title>
		<link>http://gregdoesit.com/2010/10/getting-started-with-wp7-development-learning-the-wp7-ecosystem/</link>
		<comments>http://gregdoesit.com/2010/10/getting-started-with-wp7-development-learning-the-wp7-ecosystem/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 07:43:13 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[wp7dev]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=615</guid>
		<description><![CDATA[In my previous post I&#8217;ve listed resources to help getting started with Silverlight for WP7 developers. This article aims to collect the most important resources developers should go through in order to learn the WP7 ecosystem and build decent Windows Phone 7 applications using Silverlight. Tools To Get Started Developing Download the free developer tools [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post I&#8217;ve listed resources to help <a href="http://gregdoesit.com/2010/09/getting-started-with-wp7-development-learning-siverlight/">getting started with Silverlight for WP7 developers</a>.</p>
<p>This article aims to collect the most important resources developers should go through in order to learn the WP7 ecosystem and build decent Windows Phone 7 applications using Silverlight.</p>
<h3>Tools To Get Started Developing</h3>
<ul>
<li><a href="http://go.microsoft.com/?linkid=9713250">Download the free developer tools</a> (installs Visual Studio Expression or project templates, Expression Blend for WP7 or project templates for Expression Blend 4) (you can get them from the  <a href="http://developer.windowsphone.com/windows-phone-7/">Windows Phone 7 developer site</a> developer home page as well). You&#8217;ll need this to get started with development.</li>
<li>Download the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ca23285f-bab8-47fa-b364-11553e076a9a">Windows  Phone 7 Silverlight training kit</a> &#8211; it features some very useful examples  with explained source code. I suggest going through it, or at least the parts you feel are relevant to what you want to develop.</li>
<li>Download the <a href="http://silverlight.codeplex.com/">Silverlight for Windows Phone Toolkit</a>. This component contains some essential classes for development such as GestureService (simplifying detection of gestures), DatePicker, TimePicker, WrapPanel and ToggleSwitch.</li>
</ul>
<h3>Get a Feel for Metro, the WP7 UI</h3>
<p>To develop good WP7 applications it&#8217;s important to get the feel of the WP7 user interface, Metro. I suggest going through the following resources to get familiar with it:<br />
<span id="more-615"></span></p>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?LinkID=189338">Windows Phone Design System &#8211; Codename Metro</a> &#8211; this whitepaper helps understand the motivation behind Metro</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkID=183218">Windows Phone 7  UI design guidelines</a> &#8211; worth flipping through and holding on for it for future reference.<br />
Also worth Taking a look at the structure of the <a href="http://blogs.msdn.com/b/stephanc/archive/2010/04/04/windows-phone-7-panorama-control-sample.aspx">panorama</a> and <a href="http://blogs.msdn.com/b/stephanc/archive/2010/05/09/windows-phone-7-pivot-control-sample.aspx">pivot </a>controls &#8211; these are two controls unique to WP7.</li>
<li>Pictures and videos of some conceptually well designed WP7 applications:
<ul>
<li>USGA Golf: <a href="http://www.istartedsomething.com/20100815/conceptual-usga-golf-scoring-app-microsoft-windows-phone-7-apps-done-right/"> pictures</a> and <a href="http://wmpoweruser.com/usga-golf-demo-app-for-windows-phone-7/">video</a></li>
<li><a href="http://www.youtube.com/watch?v=ovH8rLJ9qGY&amp;feature=channel">Twitter</a>,  <a href="http://www.youtube.com/watch?v=TVLqzY1-DeI&amp;p=D59CE5BA9251871B&amp;index=16">Seesmic</a>, <a href="http://www.youtube.com/watch?v=xNX2tQQtD84&amp;feature=related">Foursquare</a></li>
<li><a href="http://www.youtube.com/watch?v=yMTP92aRkB4&amp;p=D59CE5BA9251871B&amp;playnext=1&amp;index=16">Twit.TV</a>, <a href="http://www.youtube.com/watch?v=U7UjiJgAZpA">AP news</a></li>
</ul>
</li>
<li><a href="http://wp7designtemplates.codeplex.com/">Windows Phone 7 Design  Templates</a>. These are useful templates to give your application a WP7 look and feel.</li>
</ul>
<h3>Coding Resources for Windows Phone 7</h3>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ff402535%28VS.92%29.aspx">Windows  Phone development resources on MSDN</a>. These are quite in depth  tutorials on specific topics from getting started all the way to specic WP7 features like the location service, accelerometer API, trial API and so on.</li>
<li><a href="http://www.charlespetzold.com/phone/">Programming Windows Phone 7 book</a> &#8211; a great and free e-book on WP7, though not yet finalized</li>
<li><a href="http://www.msdev.com/Directory/SeriesDescription.aspx?CourseId=158">Windows  Phone 7 in 7 </a>- 20 to 30 great 7 minute video tutorials on various aspects  of Windows Phone 7 development. Highly recommended.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ff431744%28VS.92%29.aspx">WP7 code samples on MSDN</a> &#8211; if you find an application with a similar concept to  what you want to build, looking at its source code is a good start!</li>
<li><a href="http://www.jeff.wilcox.name/2010/08/windows-phone-performance/">Creating High Performing Silverlight Applications for Windows Phone</a> &#8211; a whitepaper with lots of advice on creating good and performant WP7 applications</li>
<li>If developing a larger application, it&#8217;s worth following MVVM  guidelines. Get to know MVVM in <a href="http://xsummary.com/?p=177">3 easy steps</a> and download the <a href="http://mvvmlight.codeplex.com/">MVVM Light</a> toolkit. Also learn how to <a href="http://www.smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7">unit test your WP7 project</a>.</li>
</ul>
<h3>Other Useful Resources</h3>
<ul>
<li><a href="http://metro.windowswiki.info/">130 Metro Icons for Windows  Phone 7</a>. If you&#8217;ll use the application bar, chances are you&#8217;ll use  some of these icons or want to design ones similar in style to these.</li>
<li><a href="http://www.kirupa.com/windowsphone/creating_custom_applicationbar_icon.htm">Creating a custom application bar icon</a> at kirupa.com &#8211; an article explaining how to create application bar icons that look good both on dark and white themes.</li>
<li><a href="http://wp7designtemplates.codeplex.com/">Collection of </a><a href="http://msdn.microsoft.com/en-us/library/ff769552%28VS.92%29.aspx">theme   resources for WP7</a>. Bookmark this page so you can reference as StaticResource from   your phone &#8211; you&#8217;ll be using this often when coding in Visual Studio.  Expression Blend has built in support for these though &#8211; another reason  to use it for designing your application.</li>
<li><a href="http://www.jeff.wilcox.name/2010/07/counters/">Frame rate counter on the emulator</a>: read Jeff Wilcox&#8217;s blog post on how to enable/disable it</li>
<li><a href="http://silverzine.com/resources/designing-windows-phone-7-applications/">Designing Windows Phone 7 applications </a>- a short article worth reading on basic considerations for designing WP7 applications.</li>
</ul>
<h3>Further Lists of WP7 Resources</h3>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ff402535%28VS.92%29.aspx">Windows   Phone development resources on MSDN</a>. A very well structured list pointing to detailed tutorials and whitepapers.</li>
<li><a href="http://www.jeffblankenburg.com/page/Windows-Phone-7-Resources.aspx">An extensive list of categorized WP7 resource</a>s by Jeff Blankenburg</li>
<li><a href="http://mark-kirby.co.uk/2010/the-best-resources-for-windows-phone-7-development/">Another great list of WP7 resources</a> by Mark Kirby</li>
</ul>
<p>Hope you found this list helpful, good luck with developing!</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/10/getting-started-with-wp7-development-learning-the-wp7-ecosystem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Started with WP7 Development: Learning Siverlight</title>
		<link>http://gregdoesit.com/2010/09/getting-started-with-wp7-development-learning-siverlight/</link>
		<comments>http://gregdoesit.com/2010/09/getting-started-with-wp7-development-learning-siverlight/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 14:33:40 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[wp7dev]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=623</guid>
		<description><![CDATA[This post aims to present a structured collection of resources for developers wanting to get started developing for Windows Phone 7 in Silverlight, but don&#8217;t have any Silverlight or WPF experience. I&#8217;m also aiming this post at people  who&#8217;ve started developing for WP7 without too much WPF/Silverlight experience and would like to learn more about [...]]]></description>
			<content:encoded><![CDATA[<p>This post aims to present a structured collection of resources for developers wanting to get started developing for Windows Phone 7 in Silverlight, but don&#8217;t have any Silverlight or WPF experience. I&#8217;m also aiming this post at people  who&#8217;ve started developing for WP7 without too much WPF/Silverlight experience and would like to learn more about the framework to move on.</p>
<h3>Why Silverlight?</h3>
<p>Developing for Windows Phone 7 can be done using two frameworks: Silverlight and XNA. <a href="http://en.wikipedia.org/wiki/Microsoft_XNA">XNA</a> is a framework targeting game development. Those who are looking to develop either games or graphically intensive applications are advised to use that framework.</p>
<p>Silverlight, on the other hand started off as a web application framework, a &#8220;web&#8221; light version of Windows Presentation Framework (<a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation">WPF</a>), the successor of Windows Forms. Microsoft decided to support Silverlight as the other application development framework on Windows Phone 7 next to XNA, specifically version 3.0 with some extra libraries. It&#8217;s safe to say that if one&#8217;s goal isn&#8217;t game development, the obvious (and easier) choice is to develop applications in Silverlight for WP7.</p>
<h3>What is Silverlight?</h3>
<p>Silverlight is a similar framework to Adobe Flash, allowing the developer to create applications that manipulate media, are interactive all built on the .NET platform. .NET developers will be familiar with lots of the libraries used, however Silverlight introduces several new concepts and libraries. With Out Of Browser support and Windows Phone 7 development announced, Silverlight is no longer just a web framework, but more an application development platform.</p>
<p>Some useful resources on understanding what Silverlight is:</p>
<ul>
<li><a href="http://news.cnet.com/what-is-silverlight-really/">What Is Silverlight?</a> A CNET article back from 2007, most of the content is still not outdated though.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb404700%28VS.95%29.aspx">Silverlight Overview</a> on MSDN</li>
<li><a href="http://www.silverlight.net/getstarted/overview.aspx">Overview of how Silverlight version differ</a> on silverlight.net. Remember, WP7 supports Silverlight 3.</li>
</ul>
<h3>Developer tools</h3>
<p>Silverlight development can be done with Visual Studio 2008 and upwards, I&#8217;d recommend using Visual Studio 2010 &#8211; a free, <a href="http://www.microsoft.com/express/">express version</a> is available for use. Expression Blend is an additional tool that makes creating the UI much easier.</p>
<p>If you&#8217;re planning on doing WP7 development, download the <a href="http://developer.windowsphone.com/">developer tools for WP7</a> which will either install the expression version of Visual Studio 2010 and a phone version of Expression Blend or if VS and Expression Blend are already installed, it will just add the new supported project types and the emulator.</p>
<h3>Understanding how Silverlight Works</h3>
<p>There are some key areas anyone from an OO background needs to understand to be able to develop with Silverlight.<br />
<span id="more-623"></span></p>
<h4>XAML</h4>
<p>XAML (eXtensible Markup Language) is the markup language for Silverlight. A Silverlight page always consists of a XAML file (the markup) and a code behind file (the logic). Understanding how XAML works is vital to developing any Silverlight applications.</p>
<p>Some useful resources that give on overview of XAML are:</p>
<ul>
<li><a href="http://www.silverlight.net/learn/quickstarts/xaml/">XAML quickstart</a> on silverlight.net</li>
<li><a href="http://umairsaeed.com/2010/01/17/silverlight-getting-started-with-xaml/">Getting started with XAML</a> &#8211; a short article by Umiar Saeed</li>
<li><a href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language">XAML overwiew</a> on Wikipedia</li>
</ul>
<h4>Silverlight Controls</h4>
<p>Building a Silverlight application involves with creating pages, then adding visual elements and controls to them. Silverlight has mostly the same controls as WPF &#8211; for someone who&#8217;s not worked with any of these, getting to know the basic controls can be challenging. The most important Silverlight controls to get to know are the following:</p>
<ul>
<li>Layout controls. Most important ones are Canvas, Grid and StackPanel.</li>
<li>Input &amp; selection: Button, CheckBox, ComboBox, RadioButton, Slider, TextBoxc</li>
<li>Text display: TextBlock</li>
</ul>
<p>The easiest way to explore the tools is to either add them on an example project in Visual Studio 2010 from the toolbox or in Expression Blend. There are also some good resources covering what the individual controls are designed for:</p>
<ul>
<li><a href="http://download.microsoft.com/download/c/7/5/c756bb19-3430-45fe-8088-28893a95bbef/Controls_Tutorial_01_CS.pdf">Silverlight User Interface Controls</a> &#8211; from silverlight.net (unfortunately the original article seems to be removed, this is a PDF version of it)</li>
<li><a href="http://blogs.msdn.com/b/wpfsldesigner/archive/2010/01/14/wpf-silverlight-layout-controls.aspx">Overview of Silverlight (and WPF) layout controls</a> by Karl Shifflett</li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc645075%28v=VS.95%29.aspx">Silverlight controls overview</a> on MSDN &#8211; reference documentation</li>
</ul>
<h4>Styling and templating</h4>
<p>Visuals are important in Silverlight and as such, the framework has good support for customization of visual elements. This customization can be done by using Styles on elements or by setting the Template of some controls.</p>
<p>Some resources on understanding styling and templating:</p>
<ul>
<li><a href="http://www.silverlight.net/learn/quickstarts/control-styles/">Styles overview</a> on silverlight.net</li>
<li><a href="http://www.c-sharpcorner.com/UploadFile/shakthee/Styles07272009003831AM/Styles.aspx">Using Styles in Silverlight 2</a> &#8211; this applies to Silverlight 3 and 4 as well</li>
<li><a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx">Using Style elements to better encapsulate look and feel</a> &#8211; an article by Scott Guthrie</li>
<li><a href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx">Using templates to customize a control&#8217;s look and feel</a> &#8211; again by Scott Guthrie</li>
</ul>
<h4>Dependency Properties</h4>
<p>Dependency properties are new kinds of properties Silverlight (and WPF) introduces: compared to the standard properties (the CLR properties) they provide additional services: change notification, binding, styling and resetting to default value.</p>
<p>Most of the properties on visual elements are dependency properties meaning they can be bound to, styled and change can be detected on them. Dependency properties are mostly used in bindings and styling &#8211; a lot of developers not even always aware that they&#8217;re using DPs. Understanding how they work is a stepping stone to understanding how MVVM works.</p>
<p>Some resources on understanding what dependency properties are:</p>
<ul>
<li><a href="http://joshsmithonwpf.wordpress.com/2007/05/16/demystifying-dependency-properties/">Demistifying dependency properties</a> &#8211; a nifty overview by Josh Smith</li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc221408%28v=vs.95%29.aspx">Dependency properties overview</a> on MSDN</li>
</ul>
<h4>MVVM</h4>
<p>When writing larger Silverlight applications it&#8217;s important both to separate different parts of the application, such as the model, the view and the in between layer and also to be able to test the application as much as possible. The recommended way of designing larger Silverlight (and WPF) applications is using the MVVM: Model-View-ViewModel pattern.</p>
<p>This patterns shows some similarities to the MVC (Model-View-Controller) pattern in terms that it also separates the model and the view. However instead of the controller layer, something different, a ViewModel layer is used which acts as a wrapper around the model, presenting it to the view. The pattern very heavily relies on bindings that are available in Silverlight (and WPF).</p>
<p>Anyone planning on creating a more complex Silverlight application or working on an application with a team should understand and be able to use this pattern. Some good resources on learning MVVM are the following:</p>
<ul>
<li><a href="http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/432/MVVM-for-Tarded-Folks-Like-Me-or-MVVM-and-What-it-Means-to-Me.aspx">MVVM  for tarded folks like me</a> by Jeremiah Morrill &#8211; an overview written  in a unique (and entertaining) style</li>
<li><a href="http://www.wintellect.com/CS/blogs/jlikness/archive/2010/04/14/model-view-viewmodel-mvvm-explained.aspx">MVVM explained</a> by Jeremy Likness</li>
<li><a href="http://en.wikipedia.org/wiki/Model_View_ViewModel">MVVM overview</a> on Wikipedia</li>
</ul>
<p>MVVM can be implemented on its own, but for more complex applications it&#8217;s worth using an MVVM framework that has most of the infrastructure implemented. If you&#8217;re looking into developing in WP7, the obvious choice is <a href="http://www.galasoft.ch/mvvm/getstarted/">MVVM Light</a>, the only MVVM framework at the moment I&#8217;m aware of that works on WP7, Silverlight and WPF.</p>
<p>Unfortunately there are few resources on MVVM Light &#8211; you&#8217;ll have to explore a lot on your own to master it. The few helpful ones I&#8217;m aware of are the following:</p>
<ul>
<li><a href="http://johnpapa.net/silverlight/silverlight-tv-13-mvvm-light-toolkit/">MVVM Light on Silverlight TV </a></li>
<li>MVVM Light discussions <a href="http://mvvmlight.codeplex.com/discussions?ProjectName=mvvmlight">on Codeplex</a> and MVVM Light questions <a href="http://stackoverflow.com/questions/tagged/mvvm-light">on Stackoverflow</a></li>
</ul>
<h3>Other great tutorials</h3>
<p>Others have put together great tutorials that help getting started with Silverlight. Some of the ones I&#8217;m aware of are the following:</p>
<ul>
<li><a href="http://weblogs.asp.net/scottgu/pages/silverlight-2-end-to-end-tutorial-building-a-digg-search-client.aspx">Scott Guthrie&#8217;s 8 part tutorial</a> on building a Digg-like Silverlight application</li>
<li><a href="http://www.silverlight.net/learn/quickstarts/">A list of quickstarts on silverlight.net</a> &#8211; a list of quickstarts covering different topics in Silverlight</li>
<li><a href="http://visitmix.com/Labs/rosetta/eyesofblend/">Learn to use Expression Blend</a> &#8211; learning to use Expression Blend can be extremely helpful in being more productive when building Silverlight applications</li>
</ul>
<h3>Conclusion</h3>
<p>This post aimed to collect useful resources for those wanting to gain some understanding of Silverlight before jumping on to develop for Windows Phone 7 using it, hope you found it useful.</p>
<p>In my next post I&#8217;ll be presenting a similar list of resources specifically about developing for Windows Phone 7.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/09/getting-started-with-wp7-development-learning-siverlight/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Problems when re-assigning a PathGeometry in Silverlight</title>
		<link>http://gregdoesit.com/2010/09/problems-when-re-assigning-a-pathgeometry-in-silverlight/</link>
		<comments>http://gregdoesit.com/2010/09/problems-when-re-assigning-a-pathgeometry-in-silverlight/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 14:33:48 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=600</guid>
		<description><![CDATA[I wasn&#8217;t planning in submitting (yet) another workaround for a Silverlight bug, but I stumbled across (yet) another annoying issue that causes no problems in WPF, but results in a exception being thrown in Silverlight. It definitely seems like another Silverlight bug still present in Silverlight 4. The problem I was building Paths by re-using [...]]]></description>
			<content:encoded><![CDATA[<p>I wasn&#8217;t planning in submitting (yet) another workaround for a Silverlight bug, but I stumbled across (yet) another annoying issue that causes no problems in WPF, but results in a exception being thrown in Silverlight. It definitely seems like another Silverlight bug still present in Silverlight 4.</p>
<h3>The problem</h3>
<p>I was building Paths by re-using a pre-built collection of PathGeometries. However when re-assigning a PathGeometry to another Path like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Path path1<span style="color: #008000;">;</span>
Path path2<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// These paths are in the visual tree</span>
<span style="color: #008080; font-style: italic;">// Create a PathGeometry with some points</span>
var points <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PointCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
points.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
points.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
points.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var pathFigure <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathFigure<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
pathFigure.<span style="color: #0000FF;">StartPoint</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
pathFigure.<span style="color: #0000FF;">Segments</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> PolyLineSegment<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> Points <span style="color: #008000;">=</span> points <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
var pathGeometry <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathGeometry<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
pathGeometry.<span style="color: #0000FF;">Figures</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pathFigure<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Assign this PathGeometry to both Paths</span>
path1.<span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> pathGeometry<span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// No you don't you get an ArgumentException</span>
path2.<span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> pathGeometry<span style="color: #008000;">;</span></pre></div></div>

<p>When trying to re-assign this PathGeometry, an ArgumentException was thrown with the message <em>Value does not fall within the expected range</em>. After googling around it turned out <a href="http://forums.silverlight.net/forums/p/28094/95300.aspx">others have come across this issue</a> back in mid 2008. This issue is only present in Silverlight, not WPF, which definititely suggests it is a bug.</p>
<p>However, having received a completely meaningless exception, I decided to dig deeper to at least try to understand what went wrong and find a workaround.<br />
<span id="more-600"></span></p>
<h3>The cause of the problem</h3>
<p>From the problem it was obvious that there is some problem with assigning the same PathGeometry object to multiple Path objects. Fair enough, if the same object won&#8217;t work, how about cloning it? For starters I implemented a shallow clone extension method and tested it out:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Create a shallow copy method</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> PathGeometry CloneShallow<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> PathGeometry pathGeometry<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var newPathGeometry <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathGeometry<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var figure <span style="color: #0600FF;">in</span> pathGeometry.<span style="color: #0000FF;">Figures</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        newPathGeometry.<span style="color: #0000FF;">Figures</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>figure<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">return</span> newPathGeometry<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
var pathGeometry<span style="color: #008000;">;</span>
path1.<span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> pathGeometry<span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Try assigning the shallow cloned copy of this pathGeometry to the Path</span>
<span style="color: #008080; font-style: italic;">// No you don't, this time an InvalidOperationException is thrown</span>
path2.<span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> pathGeometry.<span style="color: #0000FF;">CloneShallow</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This didn&#8217;t work either, I still got an exception. The exception was at least more helpful this time: it was an InvalidOperationException with the message <em>Element is already the child of another element</em>. This probably means that unlike WPF, the Silverlight engine probably registers PathGeometries and their figures as well in the visual tree, not allowing them to be placed under another sub tree if they are already in the tree themselves.</p>
<p>This just means that I would have to clone even deeper until the point that I get to elements that aren&#8217;t registered somewhere (probably in the visual tree) as child elements. This is what I did.</p>
<h3>The workaround</h3>
<p>The workaround that finally solved the problem was using a deep clone method that cloned all the way down until it got to Point instances which are no longer registered as children of another element (again, probably in the visual tree). This deep clone method looks like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> PathGeometry CloneDeep<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> PathGeometry pathGeometry<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var newPathGeometry <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathGeometry<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var figure <span style="color: #0600FF;">in</span> pathGeometry.<span style="color: #0000FF;">Figures</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        var newFigure <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathFigure<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        newFigure.<span style="color: #0000FF;">StartPoint</span> <span style="color: #008000;">=</span> figure.<span style="color: #0000FF;">StartPoint</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// Even figures have to be deep cloned. Assigning them directly will result in</span>
        <span style="color: #008080; font-style: italic;">//  an InvalidOperationException being thrown with the message &quot;Element is already the child of another element.&quot;</span>
        <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var segment <span style="color: #0600FF;">in</span> figure.<span style="color: #0000FF;">Segments</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// I only impemented cloning the abstract PathSegments to one implementation, </span>
            <span style="color: #008080; font-style: italic;">//  the PolyLineSegment class. If your paths use other kinds of segments, you'll need</span>
            <span style="color: #008080; font-style: italic;">//  to implement that kind of coding yourself.</span>
            var segmentAsPolyLineSegment <span style="color: #008000;">=</span> segment <span style="color: #0600FF;">as</span> PolyLineSegment<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>segmentAsPolyLineSegment <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var newSegment <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PolyLineSegment<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var point <span style="color: #0600FF;">in</span> segmentAsPolyLineSegment.<span style="color: #0000FF;">Points</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    newSegment.<span style="color: #0000FF;">Points</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>point<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                newFigure.<span style="color: #0000FF;">Segments</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>newSegment<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>                    
        <span style="color: #000000;">&#125;</span>
        newPathGeometry.<span style="color: #0000FF;">Figures</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>newFigure<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">return</span> newPathGeometry<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>To understand the problem and the workaround a bit more, here is a sample application that does the three steps: it tries to copy the PathGeometry of the top blue rectangle first by directly assigning, then by shallow cloning and finally by deep cloning:</p>
<p><object type="application/x-silverlight-2" data="data:application/x-silverlight,"  width="500" height="400"><param name="source" value="http://gregdoesit.com/wp-content/uploads/2010/09/PathGeometryProblem.xap"/></object> </p>
<p>You can download the source of this application here: <a href="http://gregdoesit.com/wp-content/uploads/2010/09/PathGeometryProblem.zip">PathGeometryProblem.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/09/problems-when-re-assigning-a-pathgeometry-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disappearing Style Setters in Silverlight 3 and WP7 &#8211; fixed in Silverlight 4</title>
		<link>http://gregdoesit.com/2010/09/disappearing-style-setters-in-silverlight-3-and-wp7-fixed-in-silverlight-4/</link>
		<comments>http://gregdoesit.com/2010/09/disappearing-style-setters-in-silverlight-3-and-wp7-fixed-in-silverlight-4/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 08:21:11 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=578</guid>
		<description><![CDATA[I&#8217;ve come across a really annoying bug in Silverlight 3 that seems to be fixed in Silverlight 4, but still present in WP7. When creating a Style object in runtime, then setting that as the Style of an element in the visual tree, the Value properties in the Setters of the original Style are set [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come across a really annoying bug in Silverlight 3 that seems to be fixed in Silverlight 4, but still present in WP7. When creating a Style object in runtime, then setting that as the Style of an element in the visual tree, the Value properties in the Setters of the original Style are set to null!</p>
<h3>The problem</h3>
<p>I&#8217;ve come across this issue because I was trying to clone styles with the following extension method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> Style Clone<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> Style style<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>style <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
    Style clonedStyle <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span>style.<span style="color: #0000FF;">TargetType</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    clonedStyle.<span style="color: #0000FF;">BasedOn</span> <span style="color: #008000;">=</span> style.<span style="color: #0000FF;">BasedOn</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>Setter setterToCopy <span style="color: #0600FF;">in</span> style.<span style="color: #0000FF;">Setters</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        clonedStyle.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Property <span style="color: #008000;">=</span> setterToCopy.<span style="color: #0000FF;">Property</span>,
            Value <span style="color: #008000;">=</span> setterToCopy.<span style="color: #0000FF;">Value</span>
        <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">return</span> clonedStyle<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As you can see, this clone method is not doing anything complicated: it is simply iterating through the Setters of the Style and creating new Setter instances with the Property and Value of the original Setters &#8211; basically deep cloning the Style itself.</p>
<h3>The issue in Silverlight 3</h3>
<p>When I did clone a Style that had been created on the fly and had been assigned a the Style of an element, the values of Setters magically were set to null in Silverlight 3. The problem is visualized using the following simple code:<br />
<span id="more-578"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Style dynamicallyCreatedStyle <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Rectangle<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
dynamicallyCreatedStyle.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Rectangle.<span style="color: #0000FF;">StrokeThicknessProperty</span>, <span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
dynamicallyCreatedStyle.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Rectangle.<span style="color: #0000FF;">StrokeProperty</span>, <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #000000;">&#40;</span>Colors.<span style="color: #0000FF;">Red</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Rectangle1.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> dynamicallyCreatedStyle.<span style="color: #0000FF;">Clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Works fine</span>
Rectangle2.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> dynamicallyCreatedStyle<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// The Value of all Setters in dynamicallyCreatedStyle are set to null because of a Silverlight 3 bug</span>
Rectangle3.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> dynamicallyCreatedStyle.<span style="color: #0000FF;">Clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// The Value of all Setters of dynamicallyCreatedStyle are null, thus Rectangle 3 won't be shown in Silverlight 3!</span></pre></div></div>

<p>See the example in Silverlight 3 below. As you can notice, the third rectangle isn&#8217;t showing as the Style that it&#8217;s assigned to it (the clone of dynamicallyCreatedStyle) has all of it&#8217;s Setter Values set to null:</p>
<p><object type="application/x-silverlight-2" data="data:application/x-silverlight,"  width="500" height="180"><param name="source" value="http://gregdoesit.com/wp-content/uploads/2010/09/StyleProblem-v3.xap"/></object> </p>
<h3>The issue in Windows Phone 7: exception being thrown</h3>
<p>In Windows Phone 7 the same code still results in incorrect behaviour with an exception being thrown.</p>
<p>The Value of the Setter is not set to null, instead it&#8217;s value can&#8217;t be determined runtime, in the debugger. Cloning of this Style is still possible, however when assigning this cloned style to in this line:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Rectangle3.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> dynamicallyCreatedStyle.<span style="color: #0000FF;">Clone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>and ArgumentException is thrown with the error message <em>The parameter is incorrect</em>.</p>
<h3>Silverlight 4: issue fixed</h3>
<p>When compiling the very same code in Silverlight 4, the Values of the Setters of the dynamically created Style are no longer set to null. Here is the same example targeted for Silverlight 4:</p>
<p><object type="application/x-silverlight-2" data="data:application/x-silverlight,"  width="500" height="180"><param name="source" value="http://gregdoesit.com/wp-content/uploads/2010/09/StyleProblem-v4.xap"/></object> </p>
<p>Using Silverlight 4, the third rectangle is showing in the application. Kudos for the Silverlight team for fixing this (as far as I was aware) undocumented issue with Styles.</p>
<p>(Note: you can download the source of the example here: <a href='http://gregdoesit.com/wp-content/uploads/2010/09/StyleProblem.zip'>Silverlight 3 Styling Issue.zip</a>)</p>
<h3>Conclusion</h3>
<p>It&#8217;s safe to say that due to this bug present in Silverlight 3 and Windows Phone 7, it&#8217;s definitely not recommended cloning Styles after they&#8217;ve been assigned to visual elements. If you&#8217;re forced to modify existing styles on visual elements, I&#8217;d suggest to constantly clone them before they&#8217;re applied to a visual element. Of course this is an expensive operation, so it&#8217;s definitely worth investigating if there are any other options available to avoid this happening in your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/09/disappearing-style-setters-in-silverlight-3-and-wp7-fixed-in-silverlight-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting the StrokeDashArray using a Style in Silverlight</title>
		<link>http://gregdoesit.com/2010/09/setting-the-strokedasharray-using-a-style-in-silverlight/</link>
		<comments>http://gregdoesit.com/2010/09/setting-the-strokedasharray-using-a-style-in-silverlight/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 14:10:12 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[bug]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=587</guid>
		<description><![CDATA[I&#8217;ve recently ran into an issue: I wanted to draw an element with a dashed stroke using a Style I&#8217;ve created on the fly. To my surprise I couldn&#8217;t. The Problem The type of the StrokeDashArray (that is defined on Shape) is a DoubleCollection. So naturally I tried setting a DoubleCollection instance as the Value [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently ran into an issue:  I wanted to draw an element with a dashed stroke using a Style I&#8217;ve created on the fly. To my surprise I couldn&#8217;t.</p>
<h3>The Problem</h3>
<p>The type of the StrokeDashArray (that is defined on Shape) is a DoubleCollection. So naturally I tried setting a DoubleCollection instance as the Value of the Setter on the Style I created:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Style ellipse2Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a DoubleCollection as the Value of the Setter for StrokeDashArrayProperty doesn't work!</span>
ellipse2Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>,<span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse2.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse2Style<span style="color: #008000;">;</span></pre></div></div>

<p><span id="more-587"></span></p>
<p>This is interesting enough as setting the StrokeDashArray property directly seems to work just fine:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Works fine</span>
Ellipse1.<span style="color: #0000FF;">StrokeDashArray</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This issue definitely suggests that this is a bug that is still present in Silverlight 4. A little searching revealed that <a href="http://forums.silverlight.net/forums/t/53869.aspx" target='_blank'>this issue has been reported in version 2</a> (almost 2 years ago!), but is still not fixed.</p>
<h3>The Workaround</h3>
<p>After some playing around I&#8217;ve found a workaround: the Setter property needs to be passed as a string, rather then a DoubleCollection. </p>
<p>The fact that this helps solve the issue is quite surprising as it suggests that there is some logic built in to the styling mechanism that in case of the StrokeDashArray property does some funky conversion from string to DoubleCollection. Personally I would&#8217;ve thought that only the XAML parser would do something similar, but it looks like this isn&#8217;t a case.</p>
<p>So the (strange) workaround is to set the value of the Setter for the StrokeDashArrayProperty to a string, just like one would do when declaring the Style in XAML. The above example can be made working using this code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Style ellipse3Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a string as the Value of the Setter for StrokeDashArrayProperty works - odd!</span>
ellipse3Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>, <span style="color: #666666;">&quot;2,2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse3.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse3Style<span style="color: #008000;">;</span></pre></div></div>

<p>As for a demo of the bug, see the following application:</p>
<p>The code behind for the application is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Works fine</span>
Ellipse1.<span style="color: #0000FF;">StrokeDashArray</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
Style ellipse2Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a DoubleCollection as the Value of the Setter for StrokeDashArrayProperty doesn't work!</span>
ellipse2Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>,<span style="color: #008000;">new</span> DoubleCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #FF0000;">2</span>, <span style="color: #FF0000;">2</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse2.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse2Style<span style="color: #008000;">;</span>
&nbsp;
Style ellipse3Style <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Style<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Ellipse<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Setting a string as the Value of the Setter for StrokeDashArrayProperty works - odd!</span>
ellipse3Style.<span style="color: #0000FF;">Setters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Setter<span style="color: #000000;">&#40;</span>Ellipse.<span style="color: #0000FF;">StrokeDashArrayProperty</span>, <span style="color: #666666;">&quot;2,2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Ellipse3.<span style="color: #0000FF;">Style</span> <span style="color: #008000;">=</span> ellipse3Style<span style="color: #008000;">;</span></pre></div></div>

<p><object type="application/x-silverlight-2" data="data:application/x-silverlight,"  width="500" height="110"><param name="source" value="http://gregdoesit.com/wp-content/uploads/2010/09/StrokeDashArrayBug.xap"/></object> </p>
<p>Download the source of the example here: <a href="http://gregdoesit.com/wp-content/uploads/2010/09/StrokeDashArrayBug.zip">StrokeDashArray Bug in Silverlight.zip</a></p>
<p>Hope this helps anyone coming across this issue!</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/09/setting-the-strokedasharray-using-a-style-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Styles in Silveright &#8211; Data Binding, Runtime Declaration and Further Advanced Topics</title>
		<link>http://gregdoesit.com/2010/08/styles-in-silveright-data-binding-runtime-declaration-and-further-advanced-topics/</link>
		<comments>http://gregdoesit.com/2010/08/styles-in-silveright-data-binding-runtime-declaration-and-further-advanced-topics/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 08:59:16 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=573</guid>
		<description><![CDATA[I&#8217;m writing a 4 part series on everything (I think) is worth knowing about styles in Silverlight. The previous parts were Silverlight Styles: an Introduction and Silverlight Styles: Advanced Topics. The third part of the series is ready and it covers the following topics: Style is a dependency property. Because of this, it supports the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing a 4 part series on everything (I think) is worth knowing about styles in Silverlight. The previous parts were <a href="http://gregdoesit.com/2010/07/styles-in-silverlight-an-introduction/">Silverlight Styles: an Introduction</a> and <a href="http://gregdoesit.com/2010/07/styles-in-silverlight-advanced-topics-part-1/">Silverlight Styles: Advanced Topics</a>.</p>
<p>The third part of the series is ready and it covers the following topics:</p>
<ul>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#stylesAreDependencyProperties">Style is a dependency property</a>. Because of this, it supports the following features:
<ul>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#dataBinding">Data binding</a> &#8211; it&#8217;s possible to bind a style to another (even though this is probably a very rare use case)</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#propertyChangedNotifications">Property change notifications</a> &#8211; it is possible to get notified when the Style property changes, a little workaround is needed though</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#clearValue">ClearValue</a> &#8211; when resetting the value of a Style, setting it to null may result in the element disappearing. It&#8217;s worth knowing what the difference between that and calling ClearValue are</li>
</ul>
</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#declaringStylesInCodeBehind">Declaring styles in code behind</a>: creating styles programmatically is more complex that via XAML but at times this technique may be useful.</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#onlyDependencyPropertiesCanBeStyled">Only dependency properties can be styled</a>, styling CLR properties will result in either a compile time error or a runtime exception.</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics#onlyFrameworkElementsHaveStyles">Only classes descending from FrameworkElement have the Style property</a> and thus can be styled.</li>
</ul>
<p>You can read the detailed article <a href="http://www.scottlogic.co.uk/blog/gergely/2010/08/styles-in-silverlight-further-advanced-topics/">on my Scott Logic blog</a> &#8211; I hope you&#8217;ll find it useful.</p>
<p>The final part of the series will explore manipulating styles in runtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/08/styles-in-silveright-data-binding-runtime-declaration-and-further-advanced-topics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Styles in Silverlight &#8211; Advanced Topics</title>
		<link>http://gregdoesit.com/2010/07/styles-in-silverlight-advanced-topics-part-1/</link>
		<comments>http://gregdoesit.com/2010/07/styles-in-silverlight-advanced-topics-part-1/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 09:55:12 +0000</pubDate>
		<dc:creator>Gergely Orosz</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gregdoesit.com/?p=567</guid>
		<description><![CDATA[I&#8217;m writing a 4 part series on everything (I think) it&#8217;s worth knowing about styles. In the second part of the series (following the previous one Styles in Silverlight &#8211; an Introduction) I&#8217;m covering the following topics: Re-Using Styles for Different Types: the TargetType of the Style can be a parent type of the target [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing a 4 part series on everything (I think) it&#8217;s worth knowing about styles. In the second part of the series (following the previous one <a href="http://gregdoesit.com/2010/07/styles-in-silverlight-an-introduction/">Styles in Silverlight &#8211; an Introduction</a>) I&#8217;m covering the following topics:</p>
<ul>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/07/styles-in-silverlight-inheritance-precedence-and-other-advanced-topics#reusingStyles">Re-Using Styles for Different Types</a>: the TargetType of the Style can be a parent type of the target object as long as it only sets properties of the parent type.<br/> So for example the Fill property of both an Ellipse and Rectangle can be styled by using a Style that&#8217;s TargetType is set to Shape (as both Ellipse and Rectangle inherit from Shape)</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/07/styles-in-silverlight-inheritance-precedence-and-other-advanced-topics/#styleBasedOn">Inheriting Styles using the BasedOn property</a>: Styles can be inherited from one another using the BasedOn property. Single inheritance is supported and the depth of inheritance is not limited.</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/07/styles-in-silverlight-inheritance-precedence-and-other-advanced-topics/#implicitStyling">Implicit styling</a>: Implicit styles allow defining a default style for all instances of a given type within the scope of the control. This feature has been introduced in Silverlight 4.</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/07/styles-in-silverlight-inheritance-precedence-and-other-advanced-topics/#stylePrecedence">Style Precedence</a>: Styles are only applied to a property if that property is not animated, has no local value set and has no value set in a template. This precedence is the same as the dependency property precedence.</li>
<li><a href="http://www.scottlogic.co.uk/blog/gergely/2010/07/styles-in-silverlight-inheritance-precedence-and-other-advanced-topics/#styleSetterPrecedence">Style Setter Precedence:</a> setters specifying the value of the same property may be declared within the same Style. The last one of them has the highest precedence and will be used.</li>
<p>You can read the (much more detailed) full article <a href="http://www.scottlogic.co.uk/blog/gergely/2010/07/styles-in-silverlight-inheritance-precedence-and-other-advanced-topics/">on my Scott Logic blog</a>. The next part of the series will cover further advanced topics such as using Styles in code behind and exploring the relationship between styles and dependency properties from a practical perspective.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://gregdoesit.com/2010/07/styles-in-silverlight-advanced-topics-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

