简体   繁体   English

Windows Phone 8中图像的自动连续滚动

[英]Automatic continuous scrolling of an image in Windows Phone 8

Let's say I have an image with size 480x800. 假设我有一个尺寸为480x800的图片。 I would like to have a square control (size 480x480) on the screen that first shows the topmost part of the image and then slowly vertically scrolls to the end of the image and when it reaches it, it scrolls back up and then down again etc. It is quite crucial that the control is smaller than the image itself since the main problem here is that if the whole image is on the screen it takes up too much space. 我想在屏幕上放置一个方形控件(大小为480x480),该控件首先显示图像的最上部分,然后缓慢垂直滚动到图像的末尾,直到到达图像的末尾,它又向上又向下滚动,依此类推控件比图像本身小是非常关键的,因为这里的主要问题是,如果整个图像都在屏幕上,则会占用太多空间。

I also don't want the user to be able to scroll the image manually since this control would be used in LongListSelector and clicking on it would take you to a new page with the whole image displayed, so the control would offer a kind of a scrollable preview of the image displayed in it and there is no need for the user to scroll manually. 我也不希望用户能够手动滚动图像,因为此控件将在LongListSelector中使用,并且单击它会将您带到显示整个图像的新页面,因此该控件将提供一种显示在其中的图像的可滚动预览,无需用户手动滚动。

I have tried to achieve this functionality with a ScrollViewer and tried to look up other ways of doing it, but I did not find anything that would work. 我尝试使用ScrollViewer实现此功能,并尝试查找其他实现方式,但没有找到任何可行的方法。 My question is if there is anything that would support this or is the best way to make a custom control that would support this kind of behavior? 我的问题是,是否有什么东西可以支持这种行为,或者是制作支持这种行为的自定义控件的最佳方法? And also if anyone has any tips of how to achieve this with a custom control, I would really appreciate it. 而且,如果有人对使用自定义控件实现此操作有任何提示,我将不胜感激。 Thanks. 谢谢。

I have figured out that making a custom control will not be needed. 我已经知道将不需要进行自定义控件。 With some more research I was able to figure out a suitable solution. 经过更多的研究,我找到了一个合适的解决方案。 I used a Border with the image set as the background with an ImageBrush and animated it with an animation that reverses automatically and repeats forever. 我使用ImageBrush将Border设置为背景,并将其设置为背景,并使用自动反转并永久重复的动画对其进行了动画处理。 I will post the solution below, it might be useful for someone. 我将在下面发布解决方案,这可能对某人有用。

<Border Height="480" Width="480" Tap="animBegin">
    <Border.Resources>
        <Storyboard x:Name="transformAnimation">
            <DoubleAnimation Storyboard.TargetName="transform" 
                             Storyboard.TargetProperty="TranslateY" 
                             From="0" To="-320" Duration="0:0:5" 
                             AutoReverse="True" RepeatBehavior="Forever" />
        </Storyboard>
    </Border.Resources>
    <Border.Background>
        <ImageBrush Stretch="UniformToFill" 
                    ImageSource="/Assets/sample.jpg"
                    AlignmentY="Top">
            <ImageBrush.Transform>
                <CompositeTransform x:Name="transform" TranslateY="0"/>
            </ImageBrush.Transform>
        </ImageBrush>
    </Border.Background>
</Border>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM