Is it possible to have a two way binding of the text content in the editor to a string property in the View Model?
2 Answers, 1 is accepted
answered on 15 Jan 2020, 10:16 AM
The SyntaxEditor doesn't support direct binding to the internal text. This is because the content is not a plain text, but a more complex document model stored in the TextDocument class. To achieve your requirement you can store the TextDocument object in your view model and work with it when necessary.
Or you can try to implement a custom synchronization between the text in your view model and the content in the TextDocument. For example, when the text in the view model changes, you can clear the document and insert the new text.
When the text in the UI changes, you can use the TextContentChanged event of the TextDocument.
privatevoidTextDocument_TextContentChanged(object sender, TextContentChangedEventArgs e)
var newText = e.AfterChangeSnapshot.GetText();
I hope this helps.
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.