<?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>Corey Schuman &#187; y</title>
	<atom:link href="http://www.85turns.com/tag/y/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.85turns.com</link>
	<description>Silverlight Consultant</description>
	<lastBuildDate>Tue, 26 Apr 2011 20:57:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Positioning in Silverlight 2</title>
		<link>http://www.85turns.com/2008/03/19/positioning-in-silverlight-2/</link>
		<comments>http://www.85turns.com/2008/03/19/positioning-in-silverlight-2/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 21:08:34 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Transforms]]></category>
		<category><![CDATA[x]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[y]]></category>

		<guid isPermaLink="false">http://simplesilverlight.wordpress.com/?p=38</guid>
		<description><![CDATA[A common mistake in Silverlight is for people to use the Canvas.Left and Canvas.Top property when positioning elements.  In Silverlight 2, there is a push towards a relative positioning model.  This makes the Margin, HorizontalAlignment, and VerticalAlignment very important (for all you CSS people the Margin starts on the Left and goes clockwise).  So, how [...]]]></description>
			<content:encoded><![CDATA[<p>A common mistake in Silverlight is for people to use the Canvas.Left and Canvas.Top property when positioning elements.  In Silverlight 2, there is a push towards a relative positioning model.  This makes the Margin, HorizontalAlignment, and VerticalAlignment very important (for all you CSS people the Margin starts on the Left and goes clockwise).  So, how do you position, move, or animate elements?  Where is the X and Y?  You can find them in the <b>TranslateTransform</b> which is part of the <b>TransformGroup</b> which is part of the <b>RenderTransform</b>.</p>
<p><b>XAML </b>(see below for this code to copy)<br />
<img src="http://simplesilverlight.files.wordpress.com/2008/03/transforms.png" alt="Transform group" /><br />
This is a pain to access from C#.  You have to access the TranslateTransform through the Children collection using the index.  What happens if you switch the positions of the Transforms in XAML?  Your code will fail.  Here is the code to access X and Y through C# (again, see below for code to copy).<br />
<img src="http://simplesilverlight.files.wordpress.com/2008/03/transforms_cs.png" alt="C Sharp translate transform" /><br />
So my question: Why not add the X, Y, ScaleX, and ScaleY to the UIElement?  This would eliminate the need to go through multiple castings in C#, it would prevent index failures if you change your transforms in XAML, and it would eliminate the misuse of the Canvas.Left and Canvas.Top properties.</p>
<p>Code to copy:</p>
<p>&lt;Grid x:Name=&#8221;LayoutRoot&#8221; Background=&#8221;White&#8221;&gt;<br />
&lt;Grid.RenderTransform&gt;<br />
&lt;TransformGroup&gt;<br />
&lt;TranslateTransform X=&#8221;0&#8243; Y=&#8221;0&#8243; /&gt;<br />
&lt;ScaleTransform ScaleX=&#8221;1&#8243; ScaleY=&#8221;0&#8243; /&gt;<br />
&lt;RotateTransform Angle=&#8221;0&#8243; /&gt;<br />
&lt;SkewTransform AngleX=&#8221;0&#8243; AngleY=&#8221;0&#8243; /&gt;<br />
&lt;/TransformGroup&gt;<br />
&lt;/Grid.RenderTransform&gt;<br />
&lt;/Grid&gt;</p>
<p><img src="/Users/corey/AppData/Local/Temp/moz-screenshot.jpg" />             ((LayoutRoot.RenderTransform as TransformGroup).Children[0] as TranslateTransform).X;<br />
((LayoutRoot.RenderTransform as TransformGroup).Children[0] as TranslateTransform).Y;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.85turns.com/2008/03/19/positioning-in-silverlight-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

