AvaloniaUI / AvaloniaEdit

Avalonia-based text editor (port of AvalonEdit)
MIT License
702 stars 138 forks source link

Can't bind text to Text property #387

Open danilwhale opened 7 months ago

danilwhale commented 7 months ago

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

antonio-valentini-ilv commented 7 months ago

I'm getting the same error 😭 Versions:

antonio-valentini-ilv commented 7 months ago

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.

enif77 commented 7 months ago

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.

Dynesshely commented 5 months ago

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

For example:

image