Skip to content

Instantly share code, notes, and snippets.

@kowill
Last active July 3, 2022 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kowill/706f68b3e71162d849a23b288818f566 to your computer and use it in GitHub Desktop.
Save kowill/706f68b3e71162d849a23b288818f566 to your computer and use it in GitHub Desktop.
AvalonEditのTextプロパティをbindableへ
using ICSharpCode.AvalonEdit;
using System;
using System.Windows;
namespace AvalonEditSample
{
public class BindableEditor : TextEditor
{
public BindableEditor()
{
}
public new string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public string BaseText
{
get { return base.Text; }
set { base.Text = value; }
}
public static DependencyProperty TextProperty =
DependencyProperty.Register(nameof(Text), typeof(string), typeof(BindableEditor),
new PropertyMetadata(string.Empty, (obj, args) =>
{
var target = (BindableEditor)obj;
if (target.BaseText != (string)args.NewValue)
target.BaseText = (string)args.NewValue;
})
);
protected override void OnTextChanged(EventArgs e)
{
if (Text != BaseText)
{
SetValue(TextProperty, BaseText);
}
base.OnTextChanged(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment