mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat.优化输出信息
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// MeoAsstGui - A part of the MeoAssistantArknights project
|
||||
// MeoAsstGui - A part of the MeoAssistantArknights project
|
||||
// Copyright (C) 2021 MistEO and Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
@@ -9,6 +9,7 @@
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -16,6 +17,7 @@ namespace MeoAsstGui
|
||||
{
|
||||
public static class AutoScroll
|
||||
{
|
||||
private static bool _autoScroll;
|
||||
public static bool GetAutoScroll(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(AutoScrollProperty);
|
||||
@@ -33,10 +35,25 @@ namespace MeoAsstGui
|
||||
{
|
||||
var scrollViewer = d as ScrollViewer;
|
||||
|
||||
if (scrollViewer != null && (bool)e.NewValue)
|
||||
if (scrollViewer != null)
|
||||
{
|
||||
scrollViewer.ScrollToBottom();
|
||||
bool alwaysScrollToEnd = (e.NewValue != null) && (bool)e.NewValue;
|
||||
if (alwaysScrollToEnd)
|
||||
{
|
||||
scrollViewer.ScrollToEnd();
|
||||
scrollViewer.ScrollChanged += ScrollChanged;
|
||||
}
|
||||
else { scrollViewer.ScrollChanged -= ScrollChanged; }
|
||||
}
|
||||
else { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); }
|
||||
}
|
||||
|
||||
private static void ScrollChanged(object sender, ScrollChangedEventArgs e)
|
||||
{
|
||||
ScrollViewer scroll = sender as ScrollViewer;
|
||||
if (scroll == null) { throw new InvalidOperationException("The attached AlwaysScrollToEnd property can only be applied to ScrollViewer instances."); }
|
||||
if (e.ExtentHeightChange == 0) { _autoScroll = scroll.VerticalOffset == scroll.ScrollableHeight; }
|
||||
if (_autoScroll && e.ExtentHeightChange != 0) { scroll.ScrollToVerticalOffset(scroll.ExtentHeight); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user