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

DataBinding to String

3 Answers 1022 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Harald
Top achievements
Rank 2
Harald asked on 20 Sep 2019, 09:46 AM

The data binding of the RadRichTextBox does not work. What am I wrong about?

Document Class:

01.public class Document : INotifyPropertyChanged
02.{
03.   private Guid _id = Guid.NewGuid();
04.   private string _title = "New Document";
05.   private string _description
06.   ....
07.   public string Description
08.   {
09.     get { return _description; }
10.     set
11.     {
12.       _description = value;
13.       NotifyPropertyChanged("Description");
14.     }
15.   }
16.}

RadRichTextBox in XAML:

01.<telerik:WizardPage x:Name="DescriptionPage" HeaderTemplate="{StaticResource headerTemplate}" BorderThickness="0">
02.....
03.  <telerik:RadRichTextBox x:Name="DocumentDescriptionTextBox" Grid.Row="2" Grid.Column="1"  Margin="10" Height="200"                                       
04.              IsSpellCheckingEnabled="True"
05.              IsContextMenuEnabled="True"
06.              IsSelectionMiniToolBarEnabled="False"
07.              IsImageMiniToolBarEnabled="False"  
08.              AllowScaling="False"
09.              DocumentInheritsDefaultStyleSettings="True"
10.                          PreviewEditorKeyDown="RichTextBox_PreviewEditorKeyDown"/>
11.  <telerik:TxtDataProvider RichTextBox="{Binding ElementName=DocumentDescriptionTextBox}"
12.               Text="{Binding Path=Description, Mode=TwoWay}"/>
13.....
14.</telerik:WizardPage>

 

Assignment of the DataContext:

1.....
2.this.DescriptionPage.DataContext = _document;
3.....

 

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 24 Sep 2019, 02:51 PM

Hello Harald,

As I don't have your entire project, I cannot be sure that I understood the issue correctly. I tried to reproduce the provided example.

XAML code:

<telerik:RadWizard>
	<telerik:RadWizard.WizardPages>
		<telerik:WizardPage x:Name="DescriptionPage">
			<StackPanel Orientation="Vertical">
				<telerik:RadRichTextBox x:Name="DocumentDescriptionTextBox" Grid.Row="2" Grid.Column="1"  Margin="10" Height="200"
												IsSpellCheckingEnabled="True"
												IsContextMenuEnabled="True"
												IsSelectionMiniToolBarEnabled="False"
												IsImageMiniToolBarEnabled="False"  
												AllowScaling="False"
												DocumentInheritsDefaultStyleSettings="True"/>
				<telerik:TxtDataProvider RichTextBox="{Binding ElementName=DocumentDescriptionTextBox}" 
												Text="{Binding Path=Description, Mode=TwoWay}" />
			</StackPanel>
		</telerik:WizardPage>
	</telerik:RadWizard.WizardPages>
</telerik:RadWizard>
Code behind:
InitializeComponent();

this.DescriptionPage.DataContext = new Document();
And the binding works for me. 

As I wrote, I am not sure what is in the place of the dots, but what I do is to add the RadRichTextBox and the TxtDataProvider into a StackPanel, because otherwise, the WizardPage takes the RadRichTextBox and TxtDataProvider as two content properties, but this data provider can take only one.

I hope this helps, but if this is not your case, please provide me with more information and I will make my best to solve it.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Harald
Top achievements
Rank 2
answered on 03 Oct 2019, 03:05 PM

This variant works:

01.<telerik:WizardPage x:Name="DescriptionPage" HeaderTemplate="{StaticResource headerTemplate}" BorderThickness="0">
02.  <Grid Margin="-11" Background="{telerik:FluentResource ResourceKey=MarkerInvertedBrush}">
03.    <StackPanel Orientation="Vertical">
04.      <TextBlock Foreground="{telerik:FluentResource ResourceKey=AccentBrush}" FontSize="{telerik:FluentResource ResourceKey=FontSizeL}" Margin="21,10,0,0" TextWrapping="Wrap" Text="Beschreibung" />
05.      <Grid>
06.        <Grid.RowDefinitions>
07.          <RowDefinition></RowDefinition>
08.        </Grid.RowDefinitions>
09.        <Grid.ColumnDefinitions>
10.          <ColumnDefinition Width="*"></ColumnDefinition>
11.        </Grid.ColumnDefinitions>
12.        <TextBox x:Name="DocumentDescriptionTextBox" Grid.Row="0" Grid.Column="0" Margin="20,10,20,10" Height="200" Text="{Binding Path=Description, Mode=TwoWay}">
13.        </TextBox>                               
14.      </Grid>
15.    </StackPanel>
16.  </Grid>
17.</telerik:WizardPage>

 

If I replaced the TextBox with a RichTextBox the data binding won't work anymore. The text captured in the RichTextBox is not stored in the object.

01.<telerik:WizardPage x:Name="DescriptionPage" HeaderTemplate="{StaticResource headerTemplate}" BorderThickness="0">
02.  <Grid Margin="-11" Background="{telerik:FluentResource ResourceKey=MarkerInvertedBrush}">
03.    <StackPanel Orientation="Vertical">
04.      <TextBlock Foreground="{telerik:FluentResource ResourceKey=AccentBrush}" FontSize="{telerik:FluentResource ResourceKey=FontSizeL}" Margin="21,10,0,0" TextWrapping="Wrap" Text="Beschreibung" />
05.      <Grid>
06.        <Grid.RowDefinitions>
07.          <RowDefinition></RowDefinition>
08.        </Grid.RowDefinitions>
09.        <Grid.ColumnDefinitions>
10.          <ColumnDefinition Width="*"></ColumnDefinition>
11.        </Grid.ColumnDefinitions>
12.        <telerik:RadRichTextBox x:Name="DocumentDescriptionTextBox" Grid.Row="0" Grid.Column="0" Margin="20,10,20,10" Height="200"                                     
13.                    IsSpellCheckingEnabled="True"
14.                    IsContextMenuEnabled="True"
15.                    IsSelectionMiniToolBarEnabled="False"
16.                    IsImageMiniToolBarEnabled="False"  
17.                    AllowScaling="False"
18.                    DocumentInheritsDefaultStyleSettings="True"
19.                                        PreviewEditorKeyDown="RichTextBox_PreviewEditorKeyDown"/>
20.        <telerik:TxtDataProvider RichTextBox="{Binding ElementName=DocumentDescriptionTextBox}"
21.                                        Text="{Binding Path=Description, Mode=TwoWay}"/>
22.      </Grid>
23.    </StackPanel>
24.  </Grid>
25.</telerik:WizardPage>

 

0
Martin
Telerik team
answered on 04 Oct 2019, 12:00 PM

Hi Harald,

I modified the sample project I used to test with the additional information you provided and still the binding is working as expected. I am attaching the example to show what exactly I am testing. Please, feel free to modify it if you still have problems achieving the expected results so we can assist you in the most efficient way.

If this example solves your case, please, let us know what was causing you issues.

I am looking forward to hearing from you.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
Harald
Top achievements
Rank 2
Answers by
Martin
Telerik team
Harald
Top achievements
Rank 2
Share this question
or