<?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>Veracity Solutions Blog &#187; grid</title>
	<atom:link href="http://blogs.veracitysolutions.com/tag/grid/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.veracitysolutions.com</link>
	<description>Software Consulting That Rocks</description>
	<lastBuildDate>Thu, 22 Apr 2010 17:21:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex Anchored Layout in Silverlight</title>
		<link>http://blogs.veracitysolutions.com/flex-anchored-layout-in-silverlight/</link>
		<comments>http://blogs.veracitysolutions.com/flex-anchored-layout-in-silverlight/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 13:45:06 +0000</pubDate>
		<dc:creator>Gregg Jensen</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[absolute]]></category>
		<category><![CDATA[anchored]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[positioning]]></category>
		<category><![CDATA[Sliverlight]]></category>

		<guid isPermaLink="false">http://blogs.veracitysolutions.com/?p=484</guid>
		<description><![CDATA[When I started using Silverlight, I was moving over from Flex, and the first thing I noticed was: Where is my anchored positioning?  
In some cases using a table (Grid) for a layout is not ideal, and if your moving over from Flex like I did, you may want to have something you&#8217;re familiar [...]]]></description>
			<content:encoded><![CDATA[<p>When I started using Silverlight, I was moving over from Flex, and the first thing I noticed was: Where is my anchored positioning?  </p>
<p>In some cases using a table (Grid) for a layout is not ideal, and if your moving over from Flex like I did, you may want to have something you&#8217;re familiar with.  This post walks though how to simulate anchored layout in Sliverlight, using a single cell and applying alignment and margin properties to its elements.</p>
<p>The following example, built in Silverlight, illustrates the types of anchored positioning:</p>
<table>
<tr>
<td>
<div id="attachment_491" class="wp-caption alignleft" style="width: 310px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutnormal.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutnormal.png" alt="Example screen normal size" width="300" height="261" class="size-medium wp-image-491" /></a><p class="wp-caption-text">Example screen normal size</p></div>
</td>
<td>
<div id="attachment_492" class="wp-caption alignleft" style="width: 310px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutstretched.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/screen_layoutstretched.png" alt="Example screen stretched" width="300" height="185" class="size-medium wp-image-492" /></a><p class="wp-caption-text">Example screen stretched</p></div>
</td>
</tr>
</table>
<p>Here is the XAML for the layout of the screen above.</p>
<div id="attachment_502" class="wp-caption aligncenter" style="width: 510px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_xaml.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_xaml.png" alt="XAML for screen" width="500" height="500" class="size-full wp-image-502" /></a><p class="wp-caption-text">XAML for screen</p></div>
<h3>One Cell, Many Possibilities</h3>
</p>
<p>As you can see from the screenshots above, as the page is stretched, the elements stretch and retain their positions also.  Normally this type of layout in Silverlight would require a Grid with 3 columns and 3 rows, and you would have to add the definitions for them as well as set the column and row properties for each element inside the Grid.  To simplify how the page is layed out, only a single cell is needed, and instead the HorizonalAlignment, VerticalAlignment, and Margins are adjusted.  A nice side effect of this type of layout, is the XAML used is significantly reduced.  I&#8217;ll go through each element in turn and explain how it&#8217;s layout is simulated from Flex.  On the left side of each explanation is the constraints as would be defined in Flex.</p>
<h3>Header</h3>
<table>
<tr>
<td>
<div id="attachment_487" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_header.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_header.png" alt="Flex layout constraints for Header" width="200" height="160" class="size-full wp-image-487" /></a><p class="wp-caption-text">Flex layout constraints for Header</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td valign="top">
<br />
<font size="2"><br />
The header of the page stays at the top and stretches left and right.  In Flex a top, left, and right position for the Header would have been set.  In Silverlight, the header of the page is anchored to the top using a VerticalAlignment of Top, and then stretches both left and right by using a HorizontalAlignment of Stretch.  A fixed Height is set, and a left Margin of 100 is applied.<br />
</font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Red&#8221; Height=&#8221;50&#8243; VerticalAlignment=&#8221;Top&#8221; HorizontalAlignment=&#8221;Stretch&#8221; Margin=&#8221;100,0,0,0&#8243;&gt;<br />
			&lt;TextBlock Text=&#8221;Header&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Navigation</h3>
<table>
<tr>
<td>
<div id="attachment_488" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_navigation.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_navigation.png" alt="Flex layout constraints for Navigation" width="200" height="160" class="size-medium wp-image-488" /></a><p class="wp-caption-text">Flex layout constraints for Navigation</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The navigation pane on the page stays vertically centered on the left.  In Flex, the verticalCenter and left positions would be set for the Navigation.  In Silverlight, VerticalAlignment is set to Stretch, and HorizontalAlignment is set to Left, with a fixed Height applied to the element.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Green&#8221; Width=&#8221;80&#8243; Height=&#8221;200&#8243; VerticalAlignment=&#8221;Stretch&#8221; HorizontalAlignment=&#8221;Left&#8221;&gt;<br />
			&lt;TextBlock Text=&#8221;Navigation&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Body</h3>
<table>
<tr>
<td>
<div id="attachment_486" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_body.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_body.png" alt="Body layout constraints in Flex" width="200" height="160" class="size-full wp-image-486" /></a><p class="wp-caption-text">Body layout constraints in Flex</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The body of the page stretches in all directions while still leaving room for the other elements.  In Flex, top, left, right, and bottom positions would be set.  In Silverlight, a VerticalAlignment and HorizontalAlignment of Stretch is set, as well as Margins on all sides.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Orange&#8221; VerticalAlignment=&#8221;Stretch&#8221; HorizontalAlignment=&#8221;Stretch&#8221; Margin=&#8221;100,80,80,80&#8243;&gt;<br />
			&lt;TextBlock Text=&#8221;Body&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Buttons</h3>
<table>
<tr>
<td>
<div id="attachment_489" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_buttons.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_buttons.png" alt="Flex layout constraints for Buttons" width="200" height="160" class="size-medium wp-image-489" /></a><p class="wp-caption-text">Flex layout constraints for Buttons</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The buttons on the page are centered horizontally on the bottom.  In Flex, the positions of bottom and right would be set.  In Silverlight, VerticalAlignment is set to Bottom, and HorizonalAlignment is set to Center with a fixed Width and Height on the element.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Blue&#8221; Width=&#8221;200&#8243; Height=&#8221;60&#8243; VerticalAlignment=&#8221;Bottom&#8221; HorizontalAlignment=&#8221;Stretch&#8221;&gt;<br />
			&lt;TextBlock Text=&#8221;Buttons&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Page</h3>
<table>
<tr>
<td>
<div id="attachment_490" class="wp-caption aligncenter" style="width: 210px"><a href="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_page.png"><img src="http://blogs.veracitysolutions.com/wp-content/uploads/2008/12/layout_page.png" alt="Flex layout constraints for Page" width="200" height="160" class="size-medium wp-image-490" /></a><p class="wp-caption-text">Flex layout constraints for Page</p></div>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td>
<font size="2"></p>
<p>The page number is in the bottom right of the page.  In Flex, a position on the bottom and right would be set.  In Silverlight, VerticalAlignment is set to Bottom, and HorizontalAlignment is set to Right, with a fixed Width and Height applied to the element.</p>
<p></font><br />
<font size="1"><br />
		&lt;Border Background=&#8221;Purple&#8221; Width=&#8221;80&#8243; Height=&#8221;60&#8243; VerticalAlignment=&#8221;Bottom&#8221; HorizontalAlignment=&#8221;Right&#8221;&gt;<br />
			&lt;TextBlock Text=&#8221;Page&#8221; Style=&#8221;{StaticResource Number}&#8221; /&gt;<br />
		&lt;/Border&gt;<br />
</font>
</td>
</tr>
</table>
<h3>Summary</h3>
</p>
<p>The use of the Grid layout can be simplified and simulate Flex anchored layout by only using a single cell, and applying alignments with margins.  Standard absolution positioning can also be achieved within a single cell grid by applying a VerticalAlignment of Top, a HorizontalAlignment of Left, and then using left and top margins for x and y respectively.  The translation from Flex anchored layout to Silverlight can be summarized by the table below:</p>
<table border="1">
<thead>
<tr>
<th>
<h4>&nbsp;Description&nbsp;</h4>
</th>
<th>
<h4>&nbsp;Flex&nbsp;</h4>
</th>
<th>
<h4>&nbsp;Silverlight&nbsp;</h4>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Top left position
</td>
<td>
top, left
</td>
<td>
VerticalAlignment=Top, HorizontalAlignment=Left
</td>
</tr>
<tr>
<td>
Bottom right position
</td>
<td>
bottom, right
</td>
<td>
VerticalAlignment=Bottom, HorizontalAlignment=Right
</td>
</tr>
<tr>
<td>
Center horizontally
</td>
<td>
center
</td>
<td>
HorizontalAlignment=Center
</td>
</tr>
<tr>
<td>
Center vertically
</td>
<td>
verticalCenter
</td>
<td>
VerticalAlignment=Center
</td>
</tr>
<tr>
<td>
Stretch horizontally
</td>
<td>
left, right
</td>
<td>
HorizontalAlignment=Stretch
</td>
</tr>
<tr>
<td>
Stretch vertically
</td>
<td>
top, bottom
</td>
<td>
VerticalAlignment=Stretch
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blogs.veracitysolutions.com/flex-anchored-layout-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
