views:

450

answers:

1

I have an issue with regards to using a ScaleTransform on a Canvas in Silverlight, the Canvas scales correctly, however the Height and Width values always remain the same.
e.g. a 100x100 Canvas scaled so it appears 200x200 is still 100x100 with regards to the Height and Width values, how can these be updated to reflect the new size.

Another related issue is how to alter the Height and Width of an element and have this Scale the Canvas or XAML element appropriately ie. setting a 100x100 element to 200x200 makes everything in it twice as big - this should be a solution where only the height and width of the element are set to alter the scale.

These questions are related to the same issue - hopefully there is a solution, that works in Silverlight 3.0


Height and Width need updated so that when this Canvas is in a ScrollViewer the Scrollbar correctly updates for the new size - this happens if the height and width is assigned manually to the new scaled size but this needs to work for all sizes.
Conversly I need to have another canvas that when its Height and Width is changed the elements inside are scaled appropriately as this will be a resizable icon for use on the same or another Canvas.


If this is not possible in Silverlight directly is there anyway of achieving this effect in code, if not in XAML, as this is possible in WPF if an ImageBrush is used, however Silverlight does not support this and need a scalable canvas, and a canvas that when scaled updates it's own height and width.

A: 

A UIElement is unaware of any transform applied to it. So it's not possible for its width and height properties to reflect the transform.


Well one option is to not use a transform at all but to use a ViewBox (from the silverlight toolkit)

The viewbox scales it content to always fill the viewbox.

Graeme Bradbury
I was not aware of this, would it be possible to update the Height and Width in code a post-ScaleTransform value for the Height and Width?
RoguePlanetoid
If you do that it'll end up even bigger, since the new width would then be scaled. Can you give some idea to what use you're going to put knowing the width and height post transform?
Graeme Bradbury
I need the Height and Width as I have an element in a ScrollViewer which updates the scrollbar by using the Height and Width of an element, so when Scaled the element is larger but the scrollbar is still "setup" for the original height/width, plus there is a height and width value displayed which needs updated too.
RoguePlanetoid
Thanks for the mention of the ViewBox, I got that from Silverlight.net but will mark this as answer as it confirms that this does the job of scaling its own contents, rather than add as my own answer.
RoguePlanetoid