wpf 无缝滚动

很早以前有项目就需要文字无缝滚动的效果但无奈当时技术不到位 人也比较懒惰(大概程序猿都是这个样子吧)

此方法并非只文字无缝其实任何内容都可以

     <ScrollViewer Name="scroll_div" Width="240" VerticalAlignment="Center" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal">
<TextBlock Name="scroll_begin">并非只可以滚动文字,此标签可以更改为任何控件内容。。</TextBlock>
<ContentControl Name="scroll_end"/>
</StackPanel>
</ScrollViewer>
     WithEvents timer As New System.Windows.Threading.DispatcherTimer
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
Dim xaml As String = System.Windows.Markup.XamlWriter.Save(scroll_begin)
scroll_end.Content = System.Windows.Markup.XamlReader.Parse(xaml)
timer.Interval = TimeSpan.FromMilliseconds()
timer.Start()
End Sub
Private Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick
If (scroll_end.ActualWidth - scroll_div.HorizontalOffset <= ) Then
scroll_div.ScrollToHorizontalOffset(scroll_div.HorizontalOffset - scroll_begin.ActualWidth)
Else
scroll_div.ScrollToHorizontalOffset(scroll_div.HorizontalOffset + )
End If
End Sub
上一篇:setter方法的内存错误


下一篇:同时兼容ie8 与ie11