Open TheJoeFin opened 3 months ago
I suggest using the modified event in code behind to update the editor and vice versa. The modified text event would look like this:
private void Editor_Modified(WinUIEditor.Editor sender, WinUIEditor.ModifiedEventArgs args)
{
if (((ModificationFlags)args.ModificationType).HasFlag(ModificationFlags.InsertText | ModificationFlags.DeleteText))
{
ViewModel.Text = sender.GetText(long.MaxValue);
}
}
And to set from the view model:
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(EditorViewModel.Text))
{
Editor.Editor.SetText(ViewModel.Text);
}
}
I’m hesitant to add a Text dependency property since the editor needs to be able to work with files in the size of gigabytes. Getting and setting the text requires a UTF-16 <-> UTF-8 conversion and an extra copy in a potentially massive string. There should be some kind of opt-in dependency property, but I’m not sure what the best way to do that would be.
I would like to use this control in my app, but it seems like there is no way to bind the text to a
viewmodel
but maybe I just missed something. Looks like a really nice project looking forward to updates!