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 滚动动画的更多相关文章

  1. 滚动条——WPF ScrollViewer的应用

    WPF ScrollViewer的应用   我们知道在一个限定高的窗体和容器中,想要把内容显示完是有些问题的,这个时候我们就要使用类似于浏览器的那个滚动条的效果了,在wpf中也同样如此,最近就碰到了这 ...

  2. WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂

    原文:WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂 先上效果图 正常样式 拖动时样式 好下面 开始吧 ==================================== ...

  3. WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化)

    原文:WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化) 注释直接写在代码里了   不太理解意思的 可以先去看看我上一篇  WPF ScrollViewer(滚动条)  自定 ...

  4. WPF中的动画——(三)时间线(TimeLine)

    WPF中的动画——(三)时间线(TimeLine) 时间线(TimeLine)表示时间段. 它提供的属性可以让控制该时间段的长度.开始时间.重复次数.该时间段内时间进度的快慢等等.在WPF中内置了如下 ...

  5. 推荐几款制作网页滚动动画的 JavaScript 库

    这里集合了几款很棒的制作网页滚动动画的 JavaScript 库和插件.它们中,有的可以帮助你在页面滚动的时候添加动感的元素动画,有的则是实现目前非常流行的全屏页面切换动画.相信借助这些插件,你也可以 ...

  6. ScrollMe – 在网页中加入各种滚动动画效果

    ScrollMe 是一款 jQuery 插件,用于给网页添加简单的滚动效果.当你向下滚动页面的时候,ScrollMe 可以缩放,旋转和平移页面上的元素.它易于设置,不需要任何自定义的 JavaScri ...

  7. 利用CSS实现带相同间隔地无缝滚动动画

    说明:因为在移动上主要利用CSS来做动画,所以没有考虑其他浏览器的兼容性,只有-webkit这个前缀,如果需要其他浏览器,请自行补齐. 首先解释一下什么是无缝滚动动画, 例如下面的例子 See the ...

  8. WPF ScrollViewer(滚动条) 自定义样式表制作 再发一套样式 细节优化

    艾尼路 出的效果图 本人嵌套 WPF ScrollViewer(滚动条) 自定义样式表制作 图文并茂 WPF ScrollViewer(滚动条) 自定义样式表制作 (改良+美化) 源代码

  9. WPF编程学习——动画

    前言 使用动画,是增强用户体验的一种有效的手段.合理的动画,可以让应用程序的界面看起来更加自然.真实.流畅.舒适,更有效地向用户展现信息,用户也更容易接受.同时也增加了软件使用的乐趣,提高用户粘度.( ...

  10. 自定义ScrollViewer的Touch事件--触摸上下移动ScrollViewer滚动到指定位置

    double mPointY;//触摸点的Y坐标 double mOffsetY;//滚动条当前位置 bool mIsTouch = false;//是否触摸 //触摸事件 private void ...

随机推荐

  1. RK3568,字符设备框架:管理同主设备号、不同次设备号设备

    字符设备框架:管理同主设备号.不同次设备号设备 以下代码针对迅为开发板RK3568,开发板系统是ubuntu20.04, 正文 以下是我写的字符设备框架,实现了管理同主设备号.不同次设备号的功能. 代 ...

  2. DDCA —— 大缓存、虚拟内存:多核缓存、NUCA缓存、页表等

    1. 缓存中的多核问题 1.1 多核系统中的缓存 Intel Montecito缓存 两个 core,每个都有一个私有的12 MB的L3缓存和一个1 MB的L2缓存,图中深蓝色部分均为L3缓存. 在多 ...

  3. ThreeJs-03材质进阶

    一.uv贴图 在3D计算机图形学中,UV映射是一种将2D纹理映射到3D模型表面的方法.在这里,"U"和"V"代表了2D纹理空间的坐标,这与2D笛卡尔坐标系统中的 ...

  4. 看不懂来打我,Vue3的watch是如何实现监听的?

    前言 watch这个API大家都很熟悉,今天这篇文章欧阳来带你搞清楚Vue3的watch是如何实现对响应式数据进行监听的.注:本文使用的Vue版本为3.5.13. 关注公众号:[前端欧阳],给自己一个 ...

  5. pip之常见错误汇总

    基本使用: 1.安装文件中的包 pip install -r requirements.txt 问题: 1. pip._vendor.urllib3.exceptions.ReadTimeoutErr ...

  6. 为什么Spring官方不推荐使用 @Autowired?

    前言 很多人刚接触 Spring 的时候,对 @Autowired 绝对是爱得深沉. 一个注解,轻松搞定依赖注入,连代码量都省了. 谁不爱呢? 但慢慢地,尤其是跑到稍微复杂点的项目里,@Autowir ...

  7. 【集成-Nacos】SpringBoot集成Nacos

    注意:以下主要演示动态配置 Nacos 是什么? Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service的首字母简称,一个更易于构建云原生 ...

  8. groovy 内存回收测试

    问题 在使用我们的开发平台时,客户怀疑我们的动态执行脚本会导致系统内存回收的问题,导致系统不响应,为此我专门针对这个问题,做一下详细的测试,看看是不是到底有什么影响. 测试步骤 1.使用编写一个控制器 ...

  9. 用谷歌经典ML方法方法来设计生成式人工智能语言模型

    上一篇:<人工智能模型学习到的知识是怎样的一种存在?> 序言:在接下来的几篇中,我们将学习如何利用 TensorFlow 来生成文本.需要注意的是,我们这里并不使用当前最热门的 Trans ...

  10. Node.js 文件读写

    1.fs模块 在node.js中,所有文件的操作都是通过fs模块来实现的.包括文件目录的创建,删除,查询以及文件的读取,写入. 在fs模块中,所有的方法都分成同步和异步两种实现,具有sync后缀的为同 ...