问题
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...
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>
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>
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