private void OnLoaded(object sender, RoutedEventArgs e)
        {
            var scrollViewer = AssociatedObject.FindVisualChildrenBreadthFirstOrSelf <ScrollViewer>().FirstOrDefault();

            if (scrollViewer is null)
            {
                throw new InvalidOperationException("ScrollViewer not found.");
            }
            else
            {
                if (scrollViewer.VerticalScrollBarVisibility == ScrollBarVisibility.Visible || scrollViewer.VerticalScrollBarVisibility == ScrollBarVisibility.Auto)
                {
                    var propertyDescriptor = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(ScrollViewer.VerticalOffsetProperty, typeof(ScrollViewer));
                    propertyDescriptor?.RemoveValueChanged(scrollViewer, OnVerticalOffsetChanged);
                    propertyDescriptor?.AddValueChanged(scrollViewer, OnVerticalOffsetChanged);

                    void OnVerticalOffsetChanged(object?sender, EventArgs args)
                    {
                        var atBottom = scrollViewer.VerticalOffset >= scrollViewer.ScrollableHeight;

                        if (atBottom)
                        {
                            CommandExecutionRequested?.Invoke(scrollViewer, EventArgs.Empty);
                        }
                    }
                }

                if (scrollViewer.HorizontalScrollBarVisibility == ScrollBarVisibility.Visible || scrollViewer.VerticalScrollBarVisibility == ScrollBarVisibility.Auto)
                {
                    var propertyDescriptor = System.ComponentModel.DependencyPropertyDescriptor.FromProperty(ScrollViewer.HorizontalOffsetProperty, typeof(ScrollViewer));
                    propertyDescriptor?.RemoveValueChanged(scrollViewer, OnHorizontalOffsetChanged);
                    propertyDescriptor?.AddValueChanged(scrollViewer, OnHorizontalOffsetChanged);

                    void OnHorizontalOffsetChanged(object?sender, EventArgs args)
                    {
                        var atBottom = scrollViewer.HorizontalOffset >= scrollViewer.ScrollableWidth;

                        if (atBottom)
                        {
                            CommandExecutionRequested?.Invoke(scrollViewer, EventArgs.Empty);
                        }
                    }
                }
            }
        }
Example #2
0
 public ICommandResult ExecuteCommand(IPlugin caller, string commandTag, params string[] args) => CommandExecutionRequested?.Invoke(caller, commandTag, args);