How to Get and Set the Text of RadRichTextBox Using MVVM

1 Answer 30 Views
RichTextBox
Ramesh
Top achievements
Rank 1
Iron
Ramesh asked on 18 May 2021, 09:58 PM

 I would like to set the value of the RadRichTextBox to a property in the view Model. and similarly I would like to get the valueof the Property and bind it to the RadRichTextBox in the WPF UI.

What would be the Syntax used in the XAML file?

I have something like this below in the XAML file.

 <telerik:RadRichTextBox x:Name="radRichTextBox" DocumentInheritsDefaultStyleSettings="True" AcceptsTab="True" AcceptsReturn="True" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" IsSelectionMiniToolBarEnabled="True" IsSpellCheckingEnabled="True" Language="en-US" IsContextMenuEnabled="True" Margin="250,190,121,70" VerticalScrollBarVisibility="Hidden"/>
  <telerik:TxtDataProvider Source="{Binding Path=Customer.Notes,ElementName=radRichTextBox, Mode=TwoWay}"/>

 

But the value is not bound to the Path "Customer.Notes" in the viewmodel.

1 Answer, 1 is accepted

Sort by
0
Accepted
Tanya
Telerik team
answered on 19 May 2021, 09:17 AM

Hello Ramesh,

You will need to set the following properties so you can successfully bind the desired property to RadRichTextBox through a TxtDataProvider:

  • RichTextBox - to define the RadRichTextBox instance the provider should be associated with 
  • Text - to define the ViewModel property path that will keep the content

Here is an example in XAML:

<telerik:TxtDataProvider RichTextBox="{Binding ElementName=radRichTextBox}" Text="{Binding Path=TextData, Mode=TwoWay}" />

You can also check the Data Providers help topic for more details on this functionality.

Regards,
Tanya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ramesh
Top achievements
Rank 1
Iron
commented on 19 May 2021, 03:10 PM

Wonderful! Thanks it works!
Tags
RichTextBox
Asked by
Ramesh
Top achievements
Rank 1
Iron
Answers by
Tanya
Telerik team
Share this question
or