在 Windows Phone 7 上使用 ScaleTransform 与 LayoutTransformer 和 Scrollviewer 时,部分图像丢失
我试图在 Windows Phone 7 应用程序的 ScrollViewer 中显示缩放图像。在应用程序页面上,我定义了如下控件:
<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>
LayoutTransformer 类来自 Silverlight 扩展项目。
我有处理 ZoomIn 和 ZoomOut 事件的方法,并且在那里执行以下操作:
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
// Zoom In
ImageScale.ScaleX = ImageScale.ScaleY = ImageScale.ScaleX + 0.5;
LayoutTransformer.ApplyLayoutTransform();
ImageScroller.InvalidateMeasure();
}
但是,当我进行放大并且更改图像时,ScrollView 控件在图像的底部和右侧有空白区域。几乎就像图像被缩放但在缩放变换之前使用原始图像的大小进行裁剪一样。
有什么想法我做错了吗?
我还创建了一个重现此问题的项目: http://dl.dropbox.com /u/2598447/ZoomTest.WP7.zip
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于收到了微软的 David Anson 的一些答复,并希望能找到解决方案。这是他的评论,但您也可以在他的博客上阅读他的回答:
您的手机可以变成机器人 - LayoutTransformer 在 Windows Phone 平台上运行良好
另外,答案中还引用了一篇 stackoverflow 文章,描述了此问题的根本原因是 Windows Phone 7 平台限制:
Silverlight 中的位图图像大小限制
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