This example shows how to handle the CustomScrollAnimation event to implement custom animation played when grid data is vertically scrolled (per-pixel scrolling). Note the view's AllowPerPixelScrolling and AllowScrollAnimation options must be enabled.
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Windows.Media.Animation
Namespace DXGrid_CustomScrollAnimation
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
grid.ItemsSource = GetData()
End Sub
Private Sub tableView1_CustomScrollAnimation(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.CustomScrollAnimationEventArgs)
e.Storyboard = New Storyboard()
Dim animation As New DoubleAnimation()
animation.From = e.OldOffset
animation.To = e.NewOffset
animation.Duration = New Duration(TimeSpan.FromMilliseconds(600))
animation.EasingFunction = New ExponentialEase() With {.Exponent = 0}
e.Storyboard.Children.Add(animation)
End Sub
Private Function GetData() As List(Of TestDataObject)
Dim _list As New List(Of TestDataObject)()
For i As Integer = 0 To 99
_list.Add(New TestDataObject() With {.ID = i, .Value = String.Format("Value {0}", i)})
Next i
Return _list
End Function
End Class
Public Class TestDataObject
Public Property ID() As Integer
Public Property Value() As String
End Class
End Namespace
<Application x:Class="DXGrid_CustomScrollAnimation.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Public Class Product
Public Property ProductName() As String
Public Property Country() As String
Public Property City() As String
Public Property UnitPrice() As Double
Public Property Quantity() As Integer
End Class
Public Class ProductList
Inherits ObservableCollection(Of Product)
Public Sub New()
MyBase.New()
Add(New Product() With {.ProductName = "Chang", .Country = "UK", .City = "Cowes", .UnitPrice = 19, .Quantity = 10})
Add(New Product() With {.ProductName = "Gravad lax", .Country = "Italy", .City = "Reggio Emilia", .UnitPrice = 12.5, .Quantity = 16})
Add(New Product() With {.ProductName = "Ravioli Angelo", .Country = "Brazil", .City = "Rio de Janeiro", .UnitPrice = 19, .Quantity = 12})
Add(New Product() With {.ProductName = "Tarte au sucre", .Country = "Germany", .City = "QUICK-Stop", .UnitPrice = 22, .Quantity = 50})
Add(New Product() With {.ProductName = "Steeleye Stout", .Country = "USA", .City = "Reggio Emilia", .UnitPrice = 18, .Quantity = 20})
Add(New Product() With {.ProductName = "Pavlova", .Country = "Austria", .City = "Graz", .UnitPrice = 21, .Quantity = 52})
Add(New Product() With {.ProductName = "Longlife Tofu", .Country = "USA", .City = "Boise", .UnitPrice = 7.75, .Quantity = 120})
Add(New Product() With {.ProductName = "Alice Mutton", .Country = "Mexico", .City = "México D.F.", .UnitPrice = 21, .Quantity = 15})
Add(New Product() With {.ProductName = "Alice Mutton", .Country = "Canada", .City = "Tsawwassen", .UnitPrice = 44, .Quantity = 16})
End Sub
End Class
<Window x:Class="DXGrid_CustomScrollAnimation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
<Grid>
<dxg:GridControl Name="grid" AutoPopulateColumns="True">
<dxg:GridControl.View>
<dxg:TableView Name="tableView1" AutoWidth="True"
AllowPerPixelScrolling="True"
ScrollAnimationMode="Custom"
CustomScrollAnimation="tableView1_CustomScrollAnimation"
AllowScrollAnimation="True"
/>
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Windows
Namespace DXGrid_CustomScrollAnimation
''' <summary>
''' Interaction logic for App.xaml
''' </summary>
Partial Public Class App
Inherits Application
End Class
End Namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace DXGrid_CustomScrollAnimation {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
grid.ItemsSource = GetData();
}
private void tableView1_CustomScrollAnimation(object sender, DevExpress.Xpf.Grid.CustomScrollAnimationEventArgs e) {
e.Storyboard = new Storyboard();
DoubleAnimation animation = new DoubleAnimation();
animation.From = e.OldOffset;
animation.To = e.NewOffset;
animation.Duration = new Duration(TimeSpan.FromMilliseconds(600));
animation.EasingFunction = new ExponentialEase() { Exponent = 0 };
e.Storyboard.Children.Add(animation);
}
private List<TestDataObject> GetData() {
List<TestDataObject> _list = new List<TestDataObject>();
for (int i = 0; i < 100; i++)
_list.Add(new TestDataObject() { ID = i, Value = string.Format("Value {0}", i) });
return _list;
}
}
public class TestDataObject {
public int ID { get; set; }
public string Value { get; set; }
}
}
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Product {
public string ProductName { get; set; }
public string Country { get; set; }
public string City { get; set; }
public double UnitPrice { get; set; }
public int Quantity { get; set; }
}
public class ProductList : ObservableCollection<Product> {
public ProductList()
: base() {
Add(new Product() { ProductName = "Chang", Country = "UK", City = "Cowes", UnitPrice = 19, Quantity = 10 });
Add(new Product() { ProductName = "Gravad lax", Country = "Italy", City = "Reggio Emilia", UnitPrice = 12.5, Quantity = 16 });
Add(new Product() { ProductName = "Ravioli Angelo", Country = "Brazil", City = "Rio de Janeiro", UnitPrice = 19, Quantity = 12 });
Add(new Product() { ProductName = "Tarte au sucre", Country = "Germany", City = "QUICK-Stop", UnitPrice = 22, Quantity = 50 });
Add(new Product() { ProductName = "Steeleye Stout", Country = "USA", City = "Reggio Emilia", UnitPrice = 18, Quantity = 20 });
Add(new Product() { ProductName = "Pavlova", Country = "Austria", City = "Graz", UnitPrice = 21, Quantity = 52 });
Add(new Product() { ProductName = "Longlife Tofu", Country = "USA", City = "Boise", UnitPrice = 7.75, Quantity = 120 });
Add(new Product() { ProductName = "Alice Mutton", Country = "Mexico", City = "México D.F.", UnitPrice = 21, Quantity = 15 });
Add(new Product() { ProductName = "Alice Mutton", Country = "Canada", City = "Tsawwassen", UnitPrice = 44, Quantity = 16 });
}
}