Wednesday, November 5, 2008

Centering Content in Xaml

so the other day i was trying to get some content to be dynamically centered. i noticed that the normal way i did it in beta 2 was not working... but that is what i get for using things in beta. i found a few convoluted ways to do it but found that the center align stuff on grid exists now and not only that but it works... here is what it looks like for my grid to take up' the whole area and my set size canvas to be centered on screen:
<usercontrol class="www.hackingsilverlight.net.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x="http://schemas.microsoft.com/winfx/2006/xaml" uc="clr-namespace:www.hackingsilverlight.net" >

<grid name="LayoutRoot" >


<grid name="ContentArea" verticalalignment="Center" horizontalalignment="Center" >

<canvas width="660" height="300" >

etc...

nice and simple and clean and you don't even have to have a clue what size your UI is. :)