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 ...
随机推荐
- DOS批处理实验
DOS批处理实验 一. 实验目的 建立一个.bat文件,清理windows垃圾文件. 二. 实验内容和要求 在Windows环境下建立一个.bat文件实现对垃圾文件.安装程序.编辑文件时产生的临时文件 ...
- [python]Gunicorn加持,轻松提升Flask超7倍性能
前言 之前学习和实际生产环境的flask都是用app.run()的默认方式启动的,因为只是公司内部服务,请求量不高,一直也没出过什么性能问题.最近接管其它小组的服务时,发现他们的服务使用Gunicor ...
- 强化学习:如何计算被环境系统截断的terminated state的value值 —— (Bootstrap returns from value estimates if episode is terminated by timeout)
本文主题:如何计算强化学习中被环境系统截断的terminated state的value值 首先解释一下什么是强化学习中的terminated state的value值,强化学习就是一个智能体(age ...
- 3.7 Linux切换目录(cd命令)
cd 命令,是 Change Directory 的缩写,用来切换工作目录. Linux 命令按照来源方式,可分为两种,分别是 Shell 内置命令和外部命令.所谓 Shell 内置命令,就是 She ...
- Visual Studio 存在版本之间冲突
1 . 检查项目中有没有重复引用的包,如果有的话卸掉一个. 2.. 检查项目中引用的包是否自带所重复的包,这样会导致项目之间引发包冲突. 举个例子: 我的项目里ICSharpCode.SharpZip ...
- 关于免费笔记软件Obsidian和免费同步,长文,保存观看
前言 这段可以略过 最早使用的笔记软件(应该说是网页摘录软件)是网文快捕 CyberArticle ,但不停换电脑后当年保存的资料基本都遗失了,那可是我翻阅众多涩涩网站的精华文章. 后来网文快捕推出了 ...
- Codeforces Round 971 (Div. 4) E 题解析
# E题 Klee's SUPER DUPER LARGE Array!!! 题目描述 思路: 对于这道题,首先观察到题目求的是最小可能值,而且数据的范围是1e9范围,所以首先可以考虑的方法就是O(l ...
- IPC最新发行了新标准:IPC-A-610J, IPC-J-STD-001J, IPC-7711/21D, IPC-2221C
IPC最新发行了新标准:IPC-A-610J, IPC-J-STD-001J, IPC-7711/21D, IPC-2221C 2024年伊始,IPC又更新了一些新的标准,大家可以及时去更新了 ...
- AI 实战篇:Spring-AI再更新!细细讲下Advisors
在2024年10月8日,Spring AI再次进行了更新,尽管当前版本仍为非稳定版本(1.0.0-M3),但博主将持续关注这些动态,并从流行的智能体视角深入解析其技术底层.目前,Spring AI仍处 ...
- Blazor 组件库 BootstrapBlazor 中Circle组件介绍
组件介绍 Circle进度环组件,是一个图表类组件.一般有两种用途: 显示某项任务进度的百分比. 统计某些指标的占比. 它的样子如下: 它的代码如下: <Circle Width="2 ...