Skip to content

Commit

Permalink
Refactor and fix AdvancedScrollWheelBehavior (renamed from SmoothScro…
Browse files Browse the repository at this point in the history
…llingBehavior)
  • Loading branch information
tom-englert committed Jul 31, 2024
1 parent 5f1991d commit a9cf94e
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 167 deletions.
105 changes: 105 additions & 0 deletions src/SampleApp/Samples/AdvancedScrollingView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<UserControl x:Class="SampleApp.Samples.AdvancedScrollingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SampleApp.Samples"
xmlns:toms="urn:TomsToolbox"
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:AdvancedScrollingViewModel}">
<Grid>
<Grid.Resources>
<SolidColorBrush Color="Transparent" x:Key="Background"></SolidColorBrush>
<LinearGradientBrush x:Key="Background1">
<GradientStop Offset="0.0" Color="Blue" />
<GradientStop Offset="0.1" Color="Red" />
<GradientStop Offset="0.2" Color="Blue" />
<GradientStop Offset="0.3" Color="Red" />
<GradientStop Offset="0.4" Color="Blue" />
<GradientStop Offset="0.5" Color="Red" />
<GradientStop Offset="0.6" Color="Blue" />
<GradientStop Offset="0.7" Color="Red" />
<GradientStop Offset="0.8" Color="Blue" />
<GradientStop Offset="0.9" Color="Red" />
<GradientStop Offset="1.0" Color="Blue" />
</LinearGradientBrush>
<VisualBrush x:Key="RepeatingTextBrush" TileMode="Tile" Viewport="0,0,200,74" ViewportUnits="Absolute">
<VisualBrush.Visual>
<Border Width="200" Height="74" BorderBrush="Transparent" BorderThickness="1">
<TextBlock Text="Repeating Text Forever&#10;And another line of text&#10;Just make it look different" FontSize="19" Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</Border>
</VisualBrush.Visual>
</VisualBrush>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0" toms:AdvancedScrollWheelBehavior.Attach="WithoutAnimation">
<Label DockPanel.Dock="Top">Regular Scrolling</Label>
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid Background="{StaticResource Background}">
<Rectangle Fill="{StaticResource RepeatingTextBrush}" Width="1500" Height="15000" />
</Grid>
</ScrollViewer>
</DockPanel>
<DockPanel Grid.Column="1">
<Label DockPanel.Dock="Top">Smooth Scrolling</Label>
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<Grid Background="{StaticResource Background}">
<Rectangle Fill="{StaticResource RepeatingTextBrush}" Width="1500" Height="15000" />
</Grid>
<i:Interaction.Behaviors>
<toms:AdvancedScrollWheelBehavior x:Name="SmoothScrollingBehavior">
<!--<toms:AdvancedScrollWheelBehavior.EasingFunction>
<QuadraticEase EasingMode="EaseOut" />
</toms:AdvancedScrollWheelBehavior.EasingFunction>-->
</toms:AdvancedScrollWheelBehavior>
</i:Interaction.Behaviors>
</ScrollViewer>
</DockPanel>
<StackPanel Grid.Column="2" Orientation="Vertical">
<Label>Enabled</Label>
<CheckBox IsChecked="{Binding IsEnabled, ElementName=SmoothScrollingBehavior}" />
<Label>Use Animation</Label>
<CheckBox IsChecked="{Binding UseScrollingAnimation, ElementName=SmoothScrollingBehavior}" />
<Label>Animation Duration</Label>
<TextBox Text="{Binding ScrollingAnimationDuration, ElementName=SmoothScrollingBehavior}" />
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="0">
<Label DockPanel.Dock="Top">Regular Scrolling</Label>
<ListBox ItemsSource="{Binding SampleData}" />
</DockPanel>
<DockPanel Grid.Column="1">
<Label DockPanel.Dock="Top">Smooth Scrolling</Label>
<ListBox ItemsSource="{Binding SampleData}">
<i:Interaction.Behaviors>
<toms:AdvancedScrollWheelBehavior x:Name="SmoothScrollingBehavior2"/>
</i:Interaction.Behaviors>
</ListBox>
</DockPanel>
<StackPanel Grid.Column="2" Orientation="Vertical">
<Label>Enabled</Label>
<CheckBox IsChecked="{Binding IsEnabled, ElementName=SmoothScrollingBehavior2}" />
<Label>Use Animation</Label>
<CheckBox IsChecked="{Binding UseScrollingAnimation, ElementName=SmoothScrollingBehavior2}" />
<Label>Animation Duration</Label>
<TextBox Text="{Binding ScrollingAnimationDuration, ElementName=SmoothScrollingBehavior2}" />
</StackPanel>
</Grid>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
/// <summary>
/// Interaction logic for SmoothScrollingView.xaml
/// </summary>
[DataTemplate(typeof(SmoothScrollingViewModel))]
public partial class SmoothScrollingView : UserControl
[DataTemplate(typeof(AdvancedScrollingViewModel))]
public partial class AdvancedScrollingView : UserControl
{
public SmoothScrollingView()
public AdvancedScrollingView()
{
InitializeComponent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace SampleApp.Samples;
[Export]
[VisualCompositionExport(RegionId.Main, Sequence = 12)]
[Shared]
public partial class SmoothScrollingViewModel : INotifyPropertyChanged
public partial class AdvancedScrollingViewModel : INotifyPropertyChanged
{
private static readonly Random _randomNumberGenerator = new();

public override string ToString()
{
return "SmoothScrolling";
return "Advanced Scrolling";
}

public ICollection<string> SampleData { get; } = Enumerable.Range(1, 1000)
Expand Down
68 changes: 0 additions & 68 deletions src/SampleApp/Samples/SmoothScrollingView.xaml

This file was deleted.

Loading

0 comments on commit a9cf94e

Please sign in to comment.