Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight WP7 Scrollviewer中的图像旋转_Silverlight_Windows Phone 7_Image Rotation - Fatal编程技术网

Silverlight WP7 Scrollviewer中的图像旋转

Silverlight WP7 Scrollviewer中的图像旋转,silverlight,windows-phone-7,image-rotation,Silverlight,Windows Phone 7,Image Rotation,在Windows Phone 7应用程序中,我希望在用户单击按钮时对图像应用90º旋转。我正在做以下工作: <Image Height="369" Name="imageView" Stretch="Uniform" Width="394"> <Image.RenderTransform> <RotateTransform Angle="0" /> </Image.RenderTransform> </Image>

在Windows Phone 7应用程序中,我希望在用户单击按钮时对图像应用90º旋转。我正在做以下工作:

<Image Height="369" Name="imageView" Stretch="Uniform" Width="394">
   <Image.RenderTransform>
      <RotateTransform Angle="0" />
   </Image.RenderTransform>
</Image>
到目前为止,一切顺利。当我将图像放在scrollviewer中时,问题出现了

<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Visible"  ScrollViewer.VerticalScrollBarVisibility="Visible" Height="389" HorizontalAlignment="Left" Margin="12,78,0,0" Name="scrollViewer" VerticalAlignment="Top" Width="409">
   <Image Height="369" Name="imageView" Stretch="Uniform" Width="394">
      <Image.RenderTransform>
         <RotateTransform Angle="0" />
      </Image.RenderTransform>
   </Image>
</ScrollViewer>

问题在于imageView.RenderTransform不是RotateTransform,而是CompositeTransform,因此请尝试以下方法:

((CompositeTransform)imageView.RenderTransform).Rotation += 90;
如果您想在XAML中直接将其指定为复合变换,您可以这样做:

<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Visible"  ScrollViewer.VerticalScrollBarVisibility="Visible" Height="389" HorizontalAlignment="Left" Margin="12,78,0,0" Name="scrollViewer" VerticalAlignment="Top" Width="409">
    <StackPanel>
         <Image Height="369" Name="imageView" Stretch="Uniform" Width="394" Source="/PhoneApp2;component/Images/lumia-920-rainbow.png">
            <Image.RenderTransform>
                <CompositeTransform Rotation="0" CenterX="197" CenterY="184" />
            </Image.RenderTransform>
        </Image>
    <StackPanel>
</ScrollViewer>


它工作正常!现在的问题是,当我滚动图像时,图像消失了。。谢谢,我没有看到,但是如果你把图像放在StackPanel中,它看起来工作正常,请查看更新的答案。我还将变换的中心移到了中间,否则图像有时会出现在可见区域之外。希望这能解决你的问题。
((CompositeTransform)imageView.RenderTransform).Rotation += 90;
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Visible"  ScrollViewer.VerticalScrollBarVisibility="Visible" Height="389" HorizontalAlignment="Left" Margin="12,78,0,0" Name="scrollViewer" VerticalAlignment="Top" Width="409">
    <StackPanel>
         <Image Height="369" Name="imageView" Stretch="Uniform" Width="394" Source="/PhoneApp2;component/Images/lumia-920-rainbow.png">
            <Image.RenderTransform>
                <CompositeTransform Rotation="0" CenterX="197" CenterY="184" />
            </Image.RenderTransform>
        </Image>
    <StackPanel>
</ScrollViewer>