Windows Phone - Marquee With Template

一个人想着一个人 提交于 2020-01-25 02:22:27

问题


In windows phone i could easily marquee a textblock. But is there any solution to marquee list of items for which i can define template and bind it to a list of items.

Thanks Gokoulane Ravi


回答1:


Although it's not a WP style...

  1. Add storyboard to page resources:

    <phone:PhoneApplicationPage.Resources>  
        <Storyboard x:Name="Scroll" RepeatBehavior="Forever">  
           <DoubleAnimation From="480" To="-480" Storyboard.TargetName="translate" Storyboard.TargetProperty="X" Duration="0:0:5" />  
        </Storyboard>  
    </phone:PhoneApplicationPage.Resources>
    
  2. Add ScrollViewer, add StackPanel inside and TextBlock inside:

           <ScrollViewer x:Name="LongScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" Margin="0,212,0,339" IsEnabled="False" >
                <StackPanel Margin="0" Height="58">
                    <TextBlock x:Name="LongTextBlock" Text="Very long, real long, it's a long text." Margin="0" Style="{StaticResource PhoneTextLargeStyle}" VerticalAlignment="Top" 
                        HorizontalAlignment="Center" TextAlignment="Center" TextTrimming="None" TextWrapping="NoWrap">
                        <TextBlock.RenderTransform>
                            <TranslateTransform x:Name="translate" />
                        </TextBlock.RenderTransform>
                    </TextBlock>
                </StackPanel>
            </ScrollViewer>
    
  3. In page's Loaded method make sure TextBlock's text is long enough for scrolling:

        Size size = new Size(double.PositiveInfinity, double.PositiveInfinity);
        this.LongTextBlock.Measure(size);
        size = this.LongTextBlock.DesiredSize;
    
        if (size.Width > this.ActualWidth)
        {
            this.Scroll.Begin();
        }
    



回答2:


You can do that. However you'll need to write custom XAML to achieve this functionality. Blend can help you over here to create that custom animation and run as marquee.



来源:https://stackoverflow.com/questions/11666542/windows-phone-marquee-with-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!