Wpf自动滚动效果
一、思路
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自动滚动效果的更多相关文章
- swiper添加了自动滚动效果,然后用手指划过页面,发现自动滚动效果不生效了
我给swiper添加了自动滚动效果,然后用手指划过页面,发现自动滚动效果不生效了,哪里出了问题呢? 添加参数 autoplayDisableOnInteraction : false,
- 实现当UILable的内容超出其范围后自动滚动效果
本文主要介绍 [当UILabel的内容超出其自身的宽度范围后,进行互动展示的效果],我们先来看一下Demo的效果图. 实际实现起来并不十分繁杂,在这里,为了开发的效率,我们使用了一个已经封装好的UIL ...
- WPF数字滚动效果
和WPF数字滚动抽奖有区别,WPF数字滚动抽奖是随机的,而这里是确定的. 为了系统演示,这个效果通宵加班写了整整6个小时,中间就上了次厕所. 代码: RollingNumberItemCtrl.xam ...
- JS平滑无缝滚动实现———实现首页广告自动滚动效果(附实例)
本文我们实现纯JS方式的滚动广告效果. 先show一下成品: 首先是网页样式: 1. #demo { 2. background: #FFF; 3. overflow:hidden; 4. borde ...
- WPF 文本滚动效果 渐变效果
<DockPanel> <StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom&qu ...
- marquee标签实现页面内容的滚动效果
页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...
- html的<marquee></marquee>标签实现滚动效果
页面的自动滚动效果,可由javascript来实现,但是今天无意中发现了一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用m ...
- 数的n次方 s.match(reg) marquee滚动效果
一.数的n次方 <script> alert(math.pow(a,5)); /*输出a的5次方*/ </script> 二. s.match(reg); s代表一个字符串,r ...
- 2016/2/26 <marquee></marquee>实现多种滚动效果
页面的自动滚动效果,可由javascript来实现,但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制.使用marquee标记 ...
随机推荐
- MessageBox显示位置
假设存在2个窗口类CImDlg与CChatDlg,如果希望MessageBox跟随CChatDlg,方法是 CChatDlg *pDlg = xxx; pDlg->MessageBox();
- RS232与RS485的功能与区别!
转载于:http://blog.csdn.net/kevinhg/article/details/7367144 RS232接口是1970年由美国电子工业协会(EIA)联合贝尔系统.调制解调器厂家及计 ...
- 使用feign上传图片
1.添加依赖,支持SpringEncoder <dependency> <groupId>io.github.openfeign.form</groupId> &l ...
- [转帖]Unix版权史
Unix版权史 http://www.ruanyifeng.com/blog/2010/03/unix_copyright_history.html 阮一峰的blog 里面写到了 system V ...
- 【转帖】2018全球公有云IaaS榜单出炉:阿里、腾讯、中国电信、金山云列前十
2018全球公有云IaaS榜单出炉:阿里.腾讯.中国电信.金山云列前十 https://news.cnblogs.com/n/628391/ 中国电信貌似就是用的华为的技术 阿里 腾讯 华为 金山 百 ...
- Luogu P4436 [HNOI/AHOI2018]游戏
题目 我们要求出\(l_i,r_i\)表示\(i\)最远能够到达的最左边和最右边的格子. 首先有一个比较简单的暴力,就是每次我们选择一个格子,然后从当前格子开始往左右暴力扩展,找到能够到达的最远的格子 ...
- python中format格式化函数
http://www.runoob.com/python/att-string-format.html
- python_0基础开始_day04
第四节 一.列表 list 数据类型之一,存储大量的,不同类型的数据 列表中只要用逗号隔开的就是一个元素 有序可变的. 1.1列表的索引 列表和字符串一样也拥有索引,但是列表可以修改: lst = [ ...
- 关于__name__=='__main__'的理解
一.总的来说,如果__name__=='__main__'成立,表示当前模块就是主程序, 如果__name__=='__main__'不成立,表示当前模块是被导入到某个模块中的,而此时__name__ ...
- DockerFile 编译语法详解
Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile来快速创建自定义的镜像,本小结首先介绍Dockerfile典型的基本结构和它支持的众多指令,并具体讲解通过这些指令来编写定 ...