I am trying to have a scaled image in a ScrollViewer in my Windows Phone 7 application. On the application page I define the controls like this:
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Name="ImageScroller" HorizontalAlignment="Center" VerticalAlignment="Center">
<layout:LayoutTransformer x:Name="LayoutTransformer">
<layout:LayoutTransformer.LayoutTransform>
<ScaleTransform x:Name="ImageScale"/>
</layout:LayoutTransformer.LayoutTransform>
<Image x:Name="Image" Margin="4" Source="{Binding ImageSource}" />
</layout:LayoutTransformer>
</ScrollViewer>
The LayoutTransformer class is coming from the Silverlight Extension project.
I have methods to handle the ZoomIn and ZoomOut events and I do the following there:
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
// Zoom In
ImageScale.ScaleX = ImageScale.ScaleY = ImageScale.ScaleX + 0.5;
LayoutTransformer.ApplyLayoutTransform();
ImageScroller.InvalidateMeasure();
}
However when I have a Zoom-In and the Image is changed the ScrollView control has empty area at the bottom and at the right side of the Image. Almost as if the Image was scaled but clipped using the size of the original image before the scale transform.
Any ideas what I am doing wrong?
I also created a project that reproduces this problem: http://dl.dropbox.com/u/2598447/ZoomTest.WP7.zip
I finally received some answer and hopefully a solution from David Anson of Microsoft. Here is his comment, but you can also read his answer on his blog:
Your phone can turn into a robot - LayoutTransformer works great on the Windows Phone platform
Also there is a stackoverflow article is referenced in the answer describing the root cause of this problem as a Windows Phone 7 platform limitation:
BitmapImage size restrictions in Silverlight