emby-toolbox/EmbyToolbox/Behaviors/AvalonEditTextBindingBehavior.cs

41 lines
1.0 KiB
C#

using System.Windows;
using ICSharpCode.AvalonEdit;
namespace EmbyToolbox.Behaviors;
public static class AvalonEditTextBindingBehavior
{
public static readonly DependencyProperty BoundTextProperty =
DependencyProperty.RegisterAttached(
"BoundText",
typeof(string),
typeof(AvalonEditTextBindingBehavior),
new PropertyMetadata(string.Empty, OnBoundTextChanged));
public static string GetBoundText(DependencyObject obj)
{
return (string)obj.GetValue(BoundTextProperty);
}
public static void SetBoundText(DependencyObject obj, string value)
{
obj.SetValue(BoundTextProperty, value);
}
private static void OnBoundTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not TextEditor editor)
{
return;
}
var nextText = e.NewValue as string ?? string.Empty;
if (editor.Text == nextText)
{
return;
}
editor.Text = nextText;
}
}