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 ...
随机推荐
- 关于如何更改Cuda的版本的一些事情
1. 网上说的很全面了,这里我把我遇到的一些问题和解决方案罗列出来,以便未来的学习和了解. 博客的好处就体现出来了,下次你再用这个东西,就直接打开你的博客照抄就行了,不用东搜西搜了,及其方便,这种碎片 ...
- Linux再学!
第三篇Linux入门 一.linux基本指令 1.Linux根目录为/,后续路径用/分隔,如/home/admin 2.Linux命令 基础格式: command: 命令本身 -options:[可选 ...
- 网站统计代码v1.0
var m = {}; var p ={}; var gifUrl = 'http://hm.iwgame.test/v.gif'; (function() { //参数组合类 m = { ck : ...
- 19、解析2_1(链、chunk、锁)
解析 shared pool 图解: library cache里面,暂时可以认为存储着: 1.SQL以及对应的执行计划(所占空间比较小): 2.存储过程.函数.触发器.包,它们编译后的对象(所占空间 ...
- 不依赖 Spring,你会如何自实现 RabbitMQ 消息的消费(一)
开心一刻 上午一好哥们微信我哥们:哥们在干嘛,晚上出来吃饭我:就我俩吗哥们:对啊我:那多没意思,我叫俩女的出来哥们:好啊,哈哈哈晚上吃完饭到家后,我给哥们发消息我:今天吃的真开心,下次继续哥们:开心尼 ...
- Jenkinsfile之语法
Pipeline支持两种语法:Declarative(在Pipeline 2.5中引入)和Scripted Pipeline.两者都支持建立连续输送Pipeline.两者都可以用于在Web UI或者a ...
- 使用 spring stream 发送消息
为什么使用spring stream ? spring stream 是用来做消息队列发送消息使用的.他隔离了各种消息队列的区别,使用统一的编程模型来发送消息. 目前支持: rabbitmq kafk ...
- less 动态样式语言
1.less的介绍 Less 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展 官方文档 2.less需要编译才能被浏览器解析 浏览器 ...
- 解决node报错ERR_OSSL_EVP_UNSUPPORTED
"scripts": {//修改启动dev方式 "dev": "SET NODE_OPTIONS=--openssl-legacy-provider ...
- CVE-2023-32233 在 Google KCTF 中的漏洞利用方案分析
这是对前文的补充,增加一种漏洞利用方案的分析,前文地址: https://www.cnblogs.com/hac425/p/17967844/cve202332233-vulnerability-an ...