This is a migrated thread and some comments may be shown as answers.

MVVM Bind Document.IsEmpty

1 Answer 145 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 24 Jun 2016, 11:12 AM
Hi,

I try to have a button disabled when there is no text in my RadRichTextBox by using MVVM. The output I need is HTML and I used to have a HtmlFormatProvider and a TxtDataProvider. I noticed with this that my typing was really slow. The datasource was not updated when I pressed enter (or send, for a chat-like application), this resulted in missing letters in mails or chats.

I wanted to try it without the TxtDataProvider, because I do not need the plain text (only for checking empty). Only thing is the disabled button, I can't check if the HTML is empty, because there always is HTML. I found a way to check if the value of the Document is empty. On DocumentChanged I can check: RadRichTextBox.Document.IsEmpty. But this can't be binded in my ViewModel because Document is not a dependencyproperty. 

It would be nice to just bind IsEnabled to a property for the RadRichTextBox, is there a way to do this? Binding to a viewmodel will also resolve the issue. Or is there a way to speed up my RadRichTextBox and the providers?

Thanks,
Rob

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 29 Jun 2016, 07:51 AM
Hello Rob,

Thank you for the very detailed information.

Indeed, the binding of the Button.IsEnabled property to the RadDocment.IsEmpty property wouldn't work as you expected, since the RadDocument.IsEmpty is a get property only. The way you could bind the Button.IsEnabled property to make the things work as you desire is the way you already did this. You could bind the TxtDataProvider's Text property with a OneWayToSource mode and to bind the button's property to another boolean property of your ViewModel which would be updated when the Text property is changed. I've tested and I didn't observe slow typing in this case.

For your convenience, I've created a small sample project which illustrates the above described approach.

I hope this helps.
If you need further assistance, please get back to us again.

Regards,
Todor
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
Rob
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or