MVVM Bind Document.IsEmpty

2 posts, 0 answers
  1. Rob
    Rob avatar
    16 posts
    Member since:
    May 2014

    Posted 24 Jun 2016 Link to this post


    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?

  2. Todor
    Todor avatar
    168 posts

    Posted 29 Jun 2016 Link to this post

    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.

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top