一、思路

1.使用ScrollView的Scroll.ScrollToVerticalOffset(offset)方法进行滚动

2.ScrollView中放置2个ListView,第一个滚动出边界后,移除,然后再动态添加一个内容相同的ListView

3.ListView设置最小高度,以保证在内容不多时同一条内容出现2次

4.每当ListView滚动出边界后,offset置0,放置offset无限增大,导致崩溃,同时方便计算ListView何时滚动出边界

二、实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading; namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
double offset = 0.0; public MainWindow()
{
InitializeComponent();
//设置定时器 ContentPanel.Children.Add(new MyListView());
ContentPanel.Children.Add(new MyListView()); for (int i = ; i < ; i++)
{
CreateInt(i);
} timer = new DispatcherTimer();
timer.Interval = new TimeSpan(); //时间间隔为一秒
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
} private void Button_Click(object sender, RoutedEventArgs e)
{
CreateRandom();
} private void CreateRandom()
{
Random random = new Random();
AddItem(random.Next().ToString());
} private void CreateInt(int i)
{
AddItem(i.ToString());
} private void AddItem(string content)
{
foreach (var lst in ContentPanel.Children)
{
if (lst is MyListView)
{
(lst as MyListView).Items.Add(content);
}
}
} private DispatcherTimer timer; private void timer_Tick(object sender, EventArgs e)
{
offset += 0.01;
Scroll.ScrollToVerticalOffset(offset);
if (offset >= (ContentPanel.Children[] as MyListView).ActualHeight)
{
Console.WriteLine("添加新list");
MyListView myListView = new MyListView();
foreach (var item in (ContentPanel.Children[] as MyListView).Items)
{
myListView.Items.Add(item);
}
ContentPanel.Children.RemoveAt();
ContentPanel.Children.Add(myListView);
offset = 0.0;
}
}
}
}

三、其他

MyListView只是一个设置了固定高度的ListView

Wpf自动滚动效果的更多相关文章

  1. swiper添加了自动滚动效果,然后用手指划过页面,发现自动滚动效果不生效了

    我给swiper添加了自动滚动效果,然后用手指划过页面,发现自动滚动效果不生效了,哪里出了问题呢? 添加参数 autoplayDisableOnInteraction : false,

  2. 实现当UILable的内容超出其范围后自动滚动效果

    本文主要介绍 [当UILabel的内容超出其自身的宽度范围后,进行互动展示的效果],我们先来看一下Demo的效果图. 实际实现起来并不十分繁杂,在这里,为了开发的效率,我们使用了一个已经封装好的UIL ...

  3. WPF数字滚动效果

    和WPF数字滚动抽奖有区别,WPF数字滚动抽奖是随机的,而这里是确定的. 为了系统演示,这个效果通宵加班写了整整6个小时,中间就上了次厕所. 代码: RollingNumberItemCtrl.xam ...

  4. JS平滑无缝滚动实现———实现首页广告自动滚动效果(附实例)

    本文我们实现纯JS方式的滚动广告效果. 先show一下成品: 首先是网页样式: 1. #demo { 2. background: #FFF; 3. overflow:hidden; 4. borde ...

  5. WPF 文本滚动效果 渐变效果

    <DockPanel> <StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom&qu ...

  6. marquee标签实现页面内容的滚动效果

    页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...

  7. html的<marquee></marquee>标签实现滚动效果

    页面的自动滚动效果,可由javascript来实现,但是今天无意中发现了一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用m ...

  8. 数的n次方 s.match(reg) marquee滚动效果

    一.数的n次方 <script> alert(math.pow(a,5)); /*输出a的5次方*/ </script> 二. s.match(reg); s代表一个字符串,r ...

  9. 2016/2/26 <marquee></marquee>实现多种滚动效果

    页面的自动滚动效果,可由javascript来实现,但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制.使用marquee标记 ...

随机推荐

  1. springMVC异常处理总结

    a.ExceptionHandlerExceptionResolver 1.@ExceptionHandler --- 统一处理一个controller中(@ExceptionHandler所在con ...

  2. linux shadow文件格式弱口令解密

    shadow格式弱口令为linux弱口令,通过kali linux 终端 john --w=字典 加上shadow文件, 扫描完成之后通过john --show 加上shadow文件出结果

  3. luoguP2015(简单树形DP)

    题目链接:https://www.luogu.org/problemnew/show/P2015 题意:给定一颗结点个数为n的树,有n-1条边,每条边有个权值,树根为1.现在给出q <=n,问剪 ...

  4. const和static const的区别(未整理)

    对于C/C++语言来讲,const就是只读的意思,只在声明中使用;static一般有2个作用,规定作用域和存储方式.对于局部变量,static规定其为静态存储方式,每次调用的初始值为上一次调用的值,调 ...

  5. python_0基础开始_day10

    第十节 一.函数进阶 动态参数 *a r g s —— 聚合位置参数,动态位置参数 默认返回的是tuple元组 def eat(*args):  # 函数的定义阶段 *聚合(打包)    print( ...

  6. SQL数据库字段数据类型详细说明

    这里先总结数据类型.MySQL中的数据类型大的方面来分,可以分为:日期和时间.数值,以及字符串.下面就分开来进行总结. 日期和时间数据类型 MySQL数据类型 含义 date 3字节,日期,格式:20 ...

  7. oppo 手机不能连接appium,提示does not have permission android.permission.CLEAR_APP_USER_DATA to clear data

    1)增加配置项noReset=true 2)除了常见开发者选项中打开usb调试,同时还需要开启以下2项,然后重启手机即可

  8. sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE6\\xB1\\x89\\xE8\\xAF\\xAD...' for column 'className' at row 1") [SQL: INSERT INTO classmessage (`classId

    sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE ...

  9. 多线程编程-- part 7 CountDownLatch

    CountDownLatch简介 CountDownLatch是通过“共享锁”实现的.在创建CountDownLatch中时,会传递一个int类型参数count,该参数是“锁计数器”的初始状态,表示该 ...

  10. 免费安装正版Xshell6+Xftp6

    先进入链接获取最新的下载地址 下载地址 填写一下姓名+邮箱,勾选需要哪个就行了 它会发给你指定邮箱一个地址,点击即可下载 安装就不用说了...