58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
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;
|
|
|
|
namespace HashCalculator.GUI
|
|
{
|
|
/// <summary>
|
|
/// MainWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
internal ViewModel ViewModel => (ViewModel)DataContext;
|
|
private bool _autoscroll = true;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void OnButtomScrollViewerScrollChanged(object sender, ScrollChangedEventArgs e)
|
|
{
|
|
var scrollViewer = (ScrollViewer)e.Source;
|
|
// User scroll event : set or unset auto-scroll mode
|
|
if (e.ExtentHeightChange == 0)
|
|
{ // Content unchanged : user scroll event
|
|
if (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight)
|
|
{ // Scroll bar is in bottom
|
|
// Set auto-scroll mode
|
|
_autoscroll = true;
|
|
}
|
|
else
|
|
{ // Scroll bar isn't in bottom
|
|
// Unset auto-scroll mode
|
|
_autoscroll = false;
|
|
}
|
|
}
|
|
|
|
// Content scroll event : auto-scroll eventually
|
|
if (_autoscroll && e.ExtentHeightChange != 0)
|
|
{ // Content changed and auto-scroll mode set
|
|
// Autoscroll
|
|
scrollViewer.ScrollToVerticalOffset(scrollViewer.ExtentHeight);
|
|
}
|
|
}
|
|
}
|
|
}
|