Zen.Wpf.Scroll 0.3.1

dotnet add package Zen.Wpf.Scroll --version 0.3.1
                    
NuGet\Install-Package Zen.Wpf.Scroll -Version 0.3.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zen.Wpf.Scroll" Version="0.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zen.Wpf.Scroll" Version="0.3.1" />
                    
Directory.Packages.props
<PackageReference Include="Zen.Wpf.Scroll" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zen.Wpf.Scroll --version 0.3.1
                    
#r "nuget: Zen.Wpf.Scroll, 0.3.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zen.Wpf.Scroll@0.3.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zen.Wpf.Scroll&version=0.3.1
                    
Install as a Cake Addin
#tool nuget:?package=Zen.Wpf.Scroll&version=0.3.1
                    
Install as a Cake Tool

🌀 Zen.Scroll

NuGet Version NuGet Downloads

Zen.Scroll 是一个 WPF 滚动动画库,为 ScrollViewer 及其内部包含 ScrollViewer 的控件(ListViewDataGridGridView 等)提供滚轮、触控板与缩放的过渡动画。启用方式为在 ScrollViewer 上设置 ScrollAnimation.IsEnabled 附加属性,不涉及模板与布局的修改。

✨ 功能特性

  • 🖱️ 滚轮滚动动画 —— 基于指数衰减模型,模拟物理滑动(初速与位移成正比)

  • ✋ 触控板滚动 —— 依手势像素速度实时调整缓动曲线与时长

  • 🔍 缩放 —— Ctrl + 滚轮,以鼠标位置为中心缩放

  • 🎚️ 可调参数 —— 滚动步长、时间常数、缩放范围以附加属性配置

  • 🎛️ 启用 —— 设置 ScrollAnimation.IsEnabled 附加属性,支持 XAML 与代码

  • ⚡ 高性能 —— GPU 加速的视觉层变换,减少内容布局触发

  • 🧩 无缝集成 —— 基于 ScrollViewer 扩展,无需重写布局或更改模板

  • 📦 轻量 —— 纯 C# 实现,无额外依赖


📦 安装

通过 NuGet 包管理器安装:

dotnet add package Zen.Wpf.Scroll

或使用 Visual Studio 的 NuGet 包管理器搜索 Zen.Wpf.Scroll 安装


🚀 快速开始

1. 单个 ScrollViewer 启用

<Window>
    <ScrollViewer ScrollAnimation.IsEnabled="True">
        
    </ScrollViewer>
</Window>

2. 全局启用(所有 ScrollViewer

 
<Application.Resources>
    <ResourceDictionary.MergedDictionaries>
        
        <ResourceDictionary Source="/TemplateStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>
</Application.Resources>

 
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style BasedOn="{StaticResource {x:Type ScrollViewer}}" TargetType="ScrollViewer">
        <Setter Property="ScrollAnimation.IsEnabled" Value="true" />
    </Style>

    <Style
        x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}"
        BasedOn="{StaticResource {x:Static GridView.GridViewScrollViewerStyleKey}}"
        TargetType="{x:Type ScrollViewer}">
        <Setter Property="ScrollAnimation.IsEnabled" Value="true" />
    </Style>
</ResourceDictionary>

3. 代码控制

// 启用/禁用
ScrollAnimation.SetIsEnabled(myScrollViewer, true);

// 检查状态
bool enabled = ScrollAnimation.GetIsEnabled(myScrollViewer);

4. 参数调节

<Style TargetType="ScrollViewer">
    <Setter Property="ScrollAnimation.IsEnabled" Value="True" />
    <Setter Property="ScrollAnimation.ScrollDelta" Value="100" />
    <Setter Property="ScrollAnimation.ScrollDuration" Value="80" />
    <Setter Property="ScrollAnimation.MinimumScale" Value="1,1" />
    <Setter Property="ScrollAnimation.MaximumScale" Value="10,10" />
    <Setter Property="ScrollAnimation.ZoomDelta" Value="0.2" />
</Style>
附加属性 说明
ScrollDelta 每格滚轮的滚动量(像素),负数表示反向滚动
ScrollDuration 滚轮滚动曲线的时间常数(毫秒)
MinimumScale 缩放下限
MaximumScale 缩放上限
ZoomDelta Ctrl + 滚轮每格的缩放量,负数表示反向缩放

超出范围的值会被就近修正,参数变更立即生效。


⚙️ 工作原理(架构概览)

分层结构

组件 职责
ScrollAnimationSmooth / ZoomAnimationSmooth 计算本帧的滚动/缩放增量,只提交目标,不触碰视觉元素
ScrollAnimationClient 动画只读的宿主契约:滚动/缩放状态与可调参数
ScrollAnimationController 输入拦截、动画生命周期、布局的暂停与恢复、可调参数的缓存与下发
ScrollAnimationTracker 跟踪滚动/缩放状态,合成内容变换与滚动条更新(含可视量 ⇄ 内容量的纯计算)
ContentCache / ScrollBarCommandHandler 位图缓存管理 / 滚动条命令接管

调用链:

graph TD
    A[用户滚轮 / 触控板输入] --> B{Controller 拦截输入}
    B --> G[动画开始:暂停内容布局]
    G --> C[ScrollAnimation 计算本帧增量]
    C --> D[Client 提交待应用目标]
    C --> E[等待每帧 FlushFrame 合成]
    D --> F[ MatrixTransform 内容变换 (GPU 合成) ]
    E --> F
    F --> H[动画结束:恢复布局并折算内容偏移]

性能优化策略

优化点 实现方式
视觉层驱动 基于内容坐标变换,完全 GPU 加速,依赖 WPF 渲染管线
布局暂停 动画期间暂停内容子树的布局更新,结束时恢复并折算偏移,逐帧的失效请求不再各自触发布局
双变换同步 元素位置与滚动偏移交替变换,实现视觉与逻辑状态双同步
参数读取 可调参数在附加属性变更时推送到控制器缓存,动画与逐帧逻辑只读字段

动画期间内容子树的布局请求会被推迟到动画结束统一处理,因此滚动过程中的元素尺寸变化不会立即生效。


📝 许可证

本项目采用 Apache License 2.0 许可证,详情请参阅 LICENSE 文件。

Enjoy smooth scrolling! 🌀

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed.  net10.0-windows7.0 is compatible.  net11.0-windows7.0 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.6.2

    • No dependencies.
  • net10.0-windows7.0

    • No dependencies.
  • net11.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.1 64 9/15/2026
0.3.0 72 9/15/2026
0.2.1 99 9/4/2026
0.1.0 110 8/27/2026