From 2fe2b3790631ed3df0685d5573579d36bf355086 Mon Sep 17 00:00:00 2001 From: David Kallesen Date: Wed, 21 Feb 2024 01:09:29 +0100 Subject: [PATCH 1/2] feat: Add IsEnabled and rename ScrollToBottom to ScrollDirection --- .../Behaviors/AutoScrollListViewBehavior.cs | 33 +++++++++++++++++-- src/Atc.Wpf/Enums/ScrollDirectionType.cs | 8 +++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/Atc.Wpf/Enums/ScrollDirectionType.cs diff --git a/src/Atc.Wpf.Controls/Behaviors/AutoScrollListViewBehavior.cs b/src/Atc.Wpf.Controls/Behaviors/AutoScrollListViewBehavior.cs index 9f68a83c..9b5a0749 100644 --- a/src/Atc.Wpf.Controls/Behaviors/AutoScrollListViewBehavior.cs +++ b/src/Atc.Wpf.Controls/Behaviors/AutoScrollListViewBehavior.cs @@ -2,7 +2,31 @@ namespace Atc.Wpf.Controls.Behaviors; public class AutoScrollListViewBehavior : Behavior { - public bool ScrollToBottom { get; set; } = true; + public static readonly DependencyProperty ScrollDirectionProperty = + DependencyProperty.Register( + nameof(ScrollDirection), + typeof(ScrollDirectionType), + typeof(AutoScrollListViewBehavior), + new PropertyMetadata(ScrollDirectionType.Bottom)); + + public ScrollDirectionType ScrollDirection + { + get => (ScrollDirectionType)GetValue(ScrollDirectionProperty); + set => SetValue(ScrollDirectionProperty, value); + } + + public static readonly DependencyProperty IsEnabledProperty = + DependencyProperty.Register( + nameof(IsEnabled), + typeof(bool), + typeof(AutoScrollListViewBehavior), + new PropertyMetadata(BooleanBoxes.FalseBox)); + + public bool IsEnabled + { + get => (bool)GetValue(IsEnabledProperty); + set => SetValue(IsEnabledProperty, value); + } protected override void OnAttached() { @@ -22,13 +46,18 @@ private void OnCollectionChanged( object? sender, NotifyCollectionChangedEventArgs e) { + if (!IsEnabled) + { + return; + } + var listView = AssociatedObject; if (listView.Items.Count <= 1) { return; } - var targetItem = ScrollToBottom + var targetItem = ScrollDirection == ScrollDirectionType.Bottom ? listView.Items[^1]! : listView.Items[0]!; diff --git a/src/Atc.Wpf/Enums/ScrollDirectionType.cs b/src/Atc.Wpf/Enums/ScrollDirectionType.cs new file mode 100644 index 00000000..ef89f22a --- /dev/null +++ b/src/Atc.Wpf/Enums/ScrollDirectionType.cs @@ -0,0 +1,8 @@ +// ReSharper disable CheckNamespace +namespace Atc.Wpf; + +public enum ScrollDirectionType +{ + Top, + Bottom, +} \ No newline at end of file From a12a11b526625e26df61f3166154ed00232b6081 Mon Sep 17 00:00:00 2001 From: David Kallesen Date: Wed, 21 Feb 2024 01:09:57 +0100 Subject: [PATCH 2/2] docs: Spelling mistake --- src/Atc.Wpf/Mvvm/ViewModelBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Atc.Wpf/Mvvm/ViewModelBase.cs b/src/Atc.Wpf/Mvvm/ViewModelBase.cs index d89e4143..712774de 100644 --- a/src/Atc.Wpf/Mvvm/ViewModelBase.cs +++ b/src/Atc.Wpf/Mvvm/ViewModelBase.cs @@ -3,7 +3,7 @@ namespace Atc.Wpf.Mvvm; /// -/// A base class for a the ViewModel class, to be used in the MVVM pattern design. +/// A base class for the ViewModel class, to be used in the MVVM pattern design. /// public abstract class ViewModelBase : ObservableObject, IViewModelBase {