AvaloniaEdit icon indicating copy to clipboard operation
AvaloniaEdit copied to clipboard

Can't bind text to Text property

Open danilwhale opened this issue 1 year ago • 5 comments

i get this when trying to build project:

Error AVLN:0004 Avalonia: Unable to find suitable setter or adder for property Text of type AvaloniaEdit:AvaloniaEdit.TextEditor for argument Avalonia.Markup.Xaml:Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension, available setter parameter lists are:
--
2 | System.String Line 138, position 50.

here is my code:

<AvaloniaEdit:TextEditor Text="{Binding Code}"
                         ShowLineNumbers="True"/>

my Code property is string, no issues happen when i bind it to TextBlock

danilwhale avatar Dec 11 '23 16:12 danilwhale

I'm getting the same error 😭 Versions:

  • Avalonia 11.0.5
  • AvaloniaEdit 11.0.5

antonio-valentini-ilv avatar Dec 13 '23 17:12 antonio-valentini-ilv

One possible workaround seems to be binding to the Document property of the TextEditor instead of the Text property, using a TextDocument instance inside the view model.

antonio-valentini-ilv avatar Dec 13 '23 18:12 antonio-valentini-ilv

One possible workaround seems to be binding to the Document property of the TextEditor instead of the Text property, using a TextDocument instance inside the view model.

That is, what I ended up using too. Its not pretty, because now my view model contains a type specific to the used UI/control.

enif77 avatar Dec 14 '23 08:12 enif77

The best practice at now is to create a converter that accept string and return Document.

For example:

image

Dynesshely avatar Feb 17 '24 12:02 Dynesshely

There is a way provided by the wiki, I love it. https://github.com/AvaloniaUI/AvaloniaEdit/wiki/MVVM#create-behaviour

realybin avatar Aug 13 '24 02:08 realybin