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 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 {