emby-toolbox/EmbyToolbox/Behaviors/TextBoxAutoScrollBehavior.cs
Emby Toolbox 6264b487fe Initial commit: Emby Toolbox (conversion scroll fix, bulk Del for tracks).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-12 21:33:47 +05:00

51 lines
1.3 KiB
C#

using System.Windows;
using System.Windows.Controls;
namespace EmbyToolbox.Behaviors;
public static class TextBoxAutoScrollBehavior
{
public static readonly DependencyProperty AutoScrollToEndProperty =
DependencyProperty.RegisterAttached(
"AutoScrollToEnd",
typeof(bool),
typeof(TextBoxAutoScrollBehavior),
new PropertyMetadata(false, OnAutoScrollToEndChanged));
public static bool GetAutoScrollToEnd(DependencyObject obj)
{
return (bool)obj.GetValue(AutoScrollToEndProperty);
}
public static void SetAutoScrollToEnd(DependencyObject obj, bool value)
{
obj.SetValue(AutoScrollToEndProperty, value);
}
private static void OnAutoScrollToEndChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not TextBox textBox)
{
return;
}
if ((bool)e.NewValue)
{
textBox.TextChanged += OnTextBoxTextChanged;
textBox.ScrollToEnd();
}
else
{
textBox.TextChanged -= OnTextBoxTextChanged;
}
}
private static void OnTextBoxTextChanged(object sender, TextChangedEventArgs e)
{
if (sender is TextBox textBox)
{
textBox.ScrollToEnd();
}
}
}