wpf ScrollViewer 滚动动画
wpf ScrollViewer 滚动动画:
<Window x:Class="WpfTest.FloatTextWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfTest"
mc:Ignorable="d"
Title="FloatTextWindow" Height="450" Width="800">
<Grid>
<ScrollViewer x:Name="scrollView" VerticalScrollBarVisibility="Auto">
<StackPanel Height="1000">
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button> <Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
<Button Background="Red" Height="55" Width="222">ghjghjhj</Button>
</StackPanel>
</ScrollViewer>
<Button Content="Scroll to Bottom" Click="Button_Click" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10" />
</Grid>
</Window>
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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes; namespace WpfTest
{
/// <summary>
/// FloatTextWindow.xaml 的交互逻辑
/// </summary>
public partial class FloatTextWindow : Window
{
public FloatTextWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// 计算滚动的目标位置
double targetVerticalOffset = scrollView.ExtentHeight - scrollView.ViewportHeight; // 创建Storyboard和DoubleAnimation
Storyboard storyboard = new Storyboard();
DoubleAnimation animation = new DoubleAnimation();
animation.From = 0;// scrollView.VerticalOffset;
animation.To = targetVerticalOffset;
animation.Duration = new Duration(TimeSpan.FromSeconds(8.5));
animation.AutoReverse = true;
animation.RepeatBehavior = RepeatBehavior.Forever;
// 指定动画的目标对象和属性
Storyboard.SetTarget(animation, scrollView);
Storyboard.SetTargetProperty(animation, new PropertyPath(ScrollViewerBehavior.VerticalOffsetProperty)); // 启动动画
storyboard.Children.Add(animation);
storyboard.Begin(this);
} }
public static class ScrollViewerBehavior
{
public static readonly DependencyProperty VerticalOffsetProperty = DependencyProperty.RegisterAttached("VerticalOffset", typeof(double), typeof(ScrollViewerBehavior), new UIPropertyMetadata(0.0, OnVerticalOffsetChanged));
public static void SetVerticalOffset(FrameworkElement target, double value) => target.SetValue(VerticalOffsetProperty, value);
public static double GetVerticalOffset(FrameworkElement target) => (double)target.GetValue(VerticalOffsetProperty);
private static void OnVerticalOffsetChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) => (target as ScrollViewer)?.ScrollToVerticalOffset((double)e.NewValue);
} }
wpf ScrollViewer 滚动动画的更多相关文章
- 滚动条——WPF ScrollViewer的应用
WPF ScrollViewer的应用 我们知道在一个限定高的窗体和容器中,想要把内容显示完是有些问题的,这个时候我们就要使用类似于浏览器的那个滚动条的效果了,在wpf中也同样如此,最近就碰到了这 ...
- WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂
原文:WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂 先上效果图 正常样式 拖动时样式 好下面 开始吧 ==================================== ...
- WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化)
原文:WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化) 注释直接写在代码里了 不太理解意思的 可以先去看看我上一篇 WPF ScrollViewer(滚动条) 自定 ...
- WPF中的动画——(三)时间线(TimeLine)
WPF中的动画——(三)时间线(TimeLine) 时间线(TimeLine)表示时间段. 它提供的属性可以让控制该时间段的长度.开始时间.重复次数.该时间段内时间进度的快慢等等.在WPF中内置了如下 ...
- 推荐几款制作网页滚动动画的 JavaScript 库
这里集合了几款很棒的制作网页滚动动画的 JavaScript 库和插件.它们中,有的可以帮助你在页面滚动的时候添加动感的元素动画,有的则是实现目前非常流行的全屏页面切换动画.相信借助这些插件,你也可以 ...
- ScrollMe – 在网页中加入各种滚动动画效果
ScrollMe 是一款 jQuery 插件,用于给网页添加简单的滚动效果.当你向下滚动页面的时候,ScrollMe 可以缩放,旋转和平移页面上的元素.它易于设置,不需要任何自定义的 JavaScri ...
- 利用CSS实现带相同间隔地无缝滚动动画
说明:因为在移动上主要利用CSS来做动画,所以没有考虑其他浏览器的兼容性,只有-webkit这个前缀,如果需要其他浏览器,请自行补齐. 首先解释一下什么是无缝滚动动画, 例如下面的例子 See the ...
- WPF ScrollViewer(滚动条) 自定义样式表制作 再发一套样式 细节优化
艾尼路 出的效果图 本人嵌套 WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂 WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化) 源代码
- WPF编程学习——动画
前言 使用动画,是增强用户体验的一种有效的手段.合理的动画,可以让应用程序的界面看起来更加自然.真实.流畅.舒适,更有效地向用户展现信息,用户也更容易接受.同时也增加了软件使用的乐趣,提高用户粘度.( ...
- 自定义ScrollViewer的Touch事件--触摸上下移动ScrollViewer滚动到指定位置
double mPointY;//触摸点的Y坐标 double mOffsetY;//滚动条当前位置 bool mIsTouch = false;//是否触摸 //触摸事件 private void ...
随机推荐
- Go下载依赖包失败的解决方法
jenkins构建job,执行go test命令报如下图的timeout错误 从报错信息中可以看出是因为下载依赖包超时 解决方法: go env查看go环境变量 GOSUMDB=sum.golang. ...
- 快速激活JRebel的方法
当谈到 JRebel 的激活时,有几种方法可以让您在 IntelliJ IDEA 中使用它.以下是一些选项: 在线激活(推荐): 安装 JRebel 插件后,点击 Jrebel Activation ...
- 机器学习专业词汇:“Lookahead horizon” 可以翻译为“前瞻视距”或“预见范围”
"Lookahead horizon" 可以翻译为"前瞻视距"或"预见范围". 在不同领域中,它可能具有稍微不同的含义: 在机器学习和人工智 ...
- 奥迪借助Karpenter为关键业务节省63%成本
原文链接: https://aws.amazon.com/cn/solutions/case-studies/audi-efficient-compute-case-study/ 翻译:cloudpi ...
- (Redis基础教程之十二) 如何解决Redis中的故障
介绍 Redis是一个开源的内存中键值数据存储.它带有几个命令,可以帮助您进行故障排除和调试.由于Redis具有内存中的键值存储的性质,因此其中许多命令都集中在内存管理上,但是还有一些其他命令对于概述 ...
- golang之context
context 用来解决 goroutine 之间退出通知.元数据传递的功能. context 使用起来非常方便.源码里对外提供了一个创建根节点 context 的函数: func Backgroun ...
- 基于python的文件监控watchdog
实时监控第三方库watchdog,其原理通过操作系统的时间触发的,不需要循环和等待 使用场景: 1.监控文件系统中文件或目录的增删改情况 2.当特定的文件被创建,删除,修改,移动时执行相应的任务 1. ...
- IE低版本cors跨域请求
标签:js 坑位 最近接到一个活动需求,但是服务端接口全是跨域的,由于js同源策略,ajax请求是不允许跨域请求的,比较流行的解决方法是jsonp或者cors,但当服务端是走cors的时候,发现IE1 ...
- M1芯片pod问题
M1芯片pod问题 换了M1芯片的mac后,在Xcode跑项目报pod错误,提示run pod install更新pod,但是去终端跑命令时又报错 然后在github上看到一个老哥的方法 https: ...
- git恢复到之前提交的记录
项目搞崩了,还提交上去了怎么办? 那当然是恢复到之前的提交记录了,那怎么操作呢? 首先,到代码托管平台找到你想恢复的提交记录(在此以github为例) 获取 commit id 首先,通过如下图操作获 ...