C
C#2y ago
mario12136

❔ How to use a readonly property for binding [AvalonEdit]?

Hello, I have created a behavior for AvalonEdit following the accepted answer here https://stackoverflow.com/questions/18964176/two-way-binding-to-avalonedit-document-text-using-mvvm. I want to have an instance of AvalonEdit that is readonly and I have a property in my viewmodel that looks liks this
public string SavedText => _document.Text;
public string SavedText => _document.Text;
I notify this property of change in one of my methods and it updates but the text of the readonly editor doesn't. The binding is OneWay and I have tried for example making a setter that does nothing for the property and the problem is solved for some reason. Note that whenever I call OnPropertyChanged(nameof(SavedText)) the property's value is updated but the callback function in the behavior is not called. I want a readonly property (doesn't make sense for it not to be) and a readonly editor and when the property is notified of changed the editor's text updates as well.
Stack Overflow
Two Way Binding to AvalonEdit Document Text using MVVM
I want to include an AvalonEdit TextEditor control into my MVVM application. The first thing I require is to be able to bind to the TextEditor.Text property so that I can display text. To do this I...
4 Replies
JakenVeina
JakenVeina2y ago
if you can make this work by just making the binding TwoWay, either the setter is triggering updates, and your intended code isn't, or there's a bug in AvalonEdit that you need to report likely the former
mario12136
mario12136OP2y ago
If I make my property
public string SavedText
{
get => _document.Text;
set => OnPropertyChanged(nameof(SavedText)) // Just example
}
public string SavedText
{
get => _document.Text;
set => OnPropertyChanged(nameof(SavedText)) // Just example
}
and mark the binding as TwoWay, it works.
JakenVeina
JakenVeina2y ago
so, yeah, OnPropertyChanged() is likely triggering the binding to update and appear to be working, and the code outside of this that's supposed to be triggering the update is likely not doing that
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server