<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Adventures of an aspiring agile developer in a not-quite agile world : XAML</title><link>http://blogs.msdn.com/agilemonkey/archive/tags/XAML/default.aspx</link><description>Tags: XAML</description><dc:language>en-CA</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Extension methods are gonna be fun!</title><link>http://blogs.msdn.com/agilemonkey/archive/2007/05/23/extension-methods-are-gonna-be-fun.aspx</link><pubDate>Wed, 23 May 2007 13:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2813964</guid><dc:creator>casper</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/agilemonkey/comments/2813964.aspx</comments><wfw:commentRss>http://blogs.msdn.com/agilemonkey/commentrss.aspx?PostID=2813964</wfw:commentRss><wfw:comment>http://blogs.msdn.com/agilemonkey/rsscomments.aspx?PostID=2813964</wfw:comment><description>
&lt;p&gt;So I've had a (very) small amount of time to play around with Orcas and Silverlight, but some of the C# 3.0 features are going to come in handy. Greg Schechter has already written about using &lt;a href="http://blogs.msdn.com/greg_schechter/archive/2007/05/19/wpf-silverlight-and-c-3-0-object-initializers.aspx" mce_href="http://blogs.msdn.com/greg_schechter/archive/2007/05/19/wpf-silverlight-and-c-3-0-object-initializers.aspx"&gt;object initializers with XAML objects&lt;/a&gt;&amp;nbsp;and back in March Scott Guthrie showed an &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx"&gt;example of extension methods&lt;/a&gt;. I've already come up with a nice little use for the latter.&lt;/p&gt;
 
&lt;p&gt;Because of its declarative nature, there are some properties you can set quite easily inside XAML, but not so easily in C# — specifying the Canvas position for an object is one of those.&lt;/p&gt;
&lt;code&gt;&amp;lt;Rectangle Canvas.Left="100" Canvas.Top="50" Width="10" Height="10/&amp;gt;&lt;/code&gt; 
&lt;pre&gt;Rectangle r = new Rectangle();&lt;br&gt;r.SetProperty&amp;lt;double&amp;gt;&lt;double&gt;(Canvas.Left, 100);&lt;br&gt;r.SetProperty&lt;/double&gt;&amp;lt;double&amp;gt;&lt;double&gt;&lt;double&gt;(Canvas.Top, 50);&lt;br&gt;&lt;/double&gt;&lt;/double&gt;&lt;/pre&gt;
Here's a nice little way object extensions can simplify your life.
&lt;pre&gt;public static class SilverlightExtensions&lt;br&gt;{&lt;br&gt;   public static void SetCanvasPosition(this Visual v, double left, double top)&lt;br&gt;   {&lt;br&gt;      v.SetValue&lt;double&gt;&amp;lt;double&amp;gt;(Canvas.LeftProperty, left);&lt;br&gt;      v.SetValue&lt;/double&gt;&amp;lt;double&amp;gt;&lt;double&gt;&lt;double&gt;(Canvas.TopProperty, top);&lt;br&gt;   }&lt;br&gt;}&lt;br&gt;&lt;/double&gt;&lt;/double&gt;&lt;/pre&gt;
&lt;p&gt;
Because I need to be able to create a ton of Rectangles programmatically, I can replace the two earlier lines of code with one&lt;/p&gt;
&lt;p&gt;&lt;code&gt;r.SetCanvasPosition(100, 50);&lt;/code&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2813964" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/agilemonkey/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/agilemonkey/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.msdn.com/agilemonkey/archive/tags/Silverlight/default.aspx">Silverlight</category></item></channel></rss>