很早以前有项目就需要文字无缝滚动的效果但无奈当时技术不到位 人也比较懒惰(大概程序猿都是这个样子吧)
此方法并非只文字无缝其实任何内容都可以
1 <ScrollViewer Name="scroll_div" Width="240" VerticalAlignment="Center" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden"> 2 <StackPanel Orientation="Horizontal"> 3 <TextBlock Name="scroll_begin">并非只可以滚动文字,此标签可以更改为任何控件内容。。</TextBlock> 4 <ContentControl Name="scroll_end"/> 5 </StackPanel> 6 </ScrollViewer>
1 WithEvents timer As New System.Windows.Threading.DispatcherTimer 2 Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) 3 Dim xaml As String = System.Windows.Markup.XamlWriter.Save(scroll_begin) 4 scroll_end.Content = System.Windows.Markup.XamlReader.Parse(xaml) 5 timer.Interval = TimeSpan.FromMilliseconds(10) 6 timer.Start() 7 End Sub 8 Private Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick 9 If (scroll_end.ActualWidth - scroll_div.HorizontalOffset <= 0) Then 10 scroll_div.ScrollToHorizontalOffset(scroll_div.HorizontalOffset - scroll_begin.ActualWidth) 11 Else 12 scroll_div.ScrollToHorizontalOffset(scroll_div.HorizontalOffset + 1) 13 End If 14 End Sub