Last active
July 3, 2022 15:28
-
-
Save kowill/706f68b3e71162d849a23b288818f566 to your computer and use it in GitHub Desktop.
AvalonEditのTextプロパティをbindableへ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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