I just started learning SL. I have tried to resize all the elements inside the canvas on its resize. But i cant find the right way.
this is what i did
- Iterate throgh the all child elements in canvas
- calaculate the scale X & Y based on the new size
- And multiply the scale values with each elements size properties
But in SL3.0 i dont find any size properties in UIelement to set the new size. below the sample code
private void testCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
{
var scaleX = e.NewSize.Width / e.PreviousSize.Width;
var scaleY = e.NewSize.Height / e.PreviousSize.Height;
for (int i = 0; i < testCanvas.Children.Count; i++)
{
UIElement ui = testCanvas.Children[i];
// but no ui.width or ui.height
}
}
Also i cant able to find an option to move each element to the new position relative to the size changed canvas…
can someone point me the right direction..
Update:
I wanted to achieve something like this in MSCUI .. For more clarity i have added some screenshots
This is how initial screen looks.
alt text http://img690.imageshack.us/img690/4611/initial.jpg
And on expanding widget, it gets zoomed and other widgets shrink
alt text http://img26.imageshack.us/img26/8725/afterexpand.jpg
I only need to do the zooing part. any ideas??
The MSCUI demo is built by Martin grayson and he has published his Drag Dock control here: http://mightymeaty.members.winisp.net/blacklight.silverlight/ (there are also now some other TileView controls available now from Telerik and Infragistics that also perform the same cool layout functions). However by default this does not support automatic content resizing.
Luckily there is a new control in the November 2009 Toolkit: ViewBox that will do what you need with minimal code.
There is a demo of this at http://silverlight.net/content/samples/sl3/toolkitcontrolsamples/run/default.html. The ViewBox demo is at the bottom of the menu on the left.
Toolkit can be downloaded from http://silverlight.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36060