WindowsFormsHost , FastColoredTextBox.
.
Text:
using System.Windows;
using System.Windows.Forms.Integration;
using FastColoredTextBoxNS;
namespace ProjectMarkdown.CustomControls
{
public class CodeTextboxHost : WindowsFormsHost
{
private readonly FastColoredTextBox _innerTextbox = new FastColoredTextBox();
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(CodeTextboxHost), new PropertyMetadata("", new PropertyChangedCallback(
(d, e) =>
{
var textBoxHost = d as CodeTextboxHost;
if (textBoxHost != null && textBoxHost._innerTextbox != null)
{
textBoxHost._innerTextbox.Text = textBoxHost.GetValue(e.Property) as string;
}
}), null));
public CodeTextboxHost()
{
Child = _innerTextbox;
_innerTextbox.TextChanged += _innerTextbox_TextChanged;
}
private void _innerTextbox_TextChanged(object sender, TextChangedEventArgs e)
{
SetValue(TextProperty, _innerTextbox.Text);
}
public string Text
{
get { return (string) GetValue(TextProperty); }
set
{
SetValue(TextProperty, value);
}
}
}
}
XAML:
<customControls:CodeTextboxHost Text="{Binding MyTextField, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>