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

Binding Document

12 Answers 580 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rieni De Rijke
Top achievements
Rank 1
Rieni De Rijke asked on 30 Mar 2011, 09:14 PM
I've seen a few examples -    most Silverlight  :-(     - where you bind the RadRichTextBox to an "item"-object or data from a DataBase.
But how could this be done to a RadRichTextBox.Document.
Say I get a datarow from a table and I want to create a new document with content/text from this datarow.

12 Answers, 1 is accepted

Sort by
0
bernd kopp
Top achievements
Rank 1
answered on 31 Mar 2011, 09:25 PM
I second that question because I have the same problem trying your new RichTextBox for WPF.
There is no API, no Documentation for WPF. I tried to do it logically and searching for a Text,Document,RTF Property on the Provider,FlowDocument and RichTextBox.
I haven`t found much and this is my version of code thats not working.

What do I wrong?

<
DataGridTemplateColumn Width="*" Header="Content">        <DataGridTemplateColumn.CellTemplate>             <DataTemplate>                      <Grid>                      <Grid.RowDefinitions>                          <RowDefinition Height="*" />                           <RowDefinition />                      </Grid.RowDefinitions>                                                               <telerik:RadRichTextBox Document="{Binding Content,UpdateSourceTrigger=LostFocus}" Grid.Row="0" x:Name="RTFBox" />                           <telerikProvider:RtfDataProvider  Grid.Row="1"  Rtf="{Binding ElementName=RTFBox,Path=Document}" />                   </Grid>             </DataTemplate>       </DataGridTemplateColumn.CellTemplate>   </DataGridTemplateColumn>
0
bernd kopp
Top achievements
Rank 1
answered on 01 Apr 2011, 09:06 AM
Or task ask concretely: What is the DependencyProperty I have to bind to in the Path="NameOfDependencyPropertyOfRichTextBox"

Usually the DP would be Document or Text, but I can not find any of them.
0
Iva Toteva
Telerik team
answered on 01 Apr 2011, 04:04 PM
Hello Rieni De Rijke, Bernd Kopp

The documentation for the WPF RichTextBox is still not ready, but you can refer to the Silverlight article on data providers. The only difference is that the data providers have to be in the visual tree, like in Bernd's snippet, but he missed to bind the RichTextBox property of the data provider.
@Bernd: Here is the revised version of your code:

<DataTemplate>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <telerik:RadRichTextBox Grid.Row="0" x:Name="RTFBox" />
        <telerikProvider:RtfDataProvider Grid.Row="1" Rtf="{Binding Content}" UpdateSourceTrigger="LostFocus" RichTextBox="{Binding ElementName=RTFBox}" />
    </Grid>
</DataTemplate>

You can also specify the BindingMode on the Rtf property of the data provider.

Best wishes,

Iva
the Telerik team
0
bernd kopp
Top achievements
Rank 1
answered on 01 Apr 2011, 09:16 PM
Hello Iva,

I tried your code and I get this Exception in my output window when the MIcrosoft DataGrid with YOUR templated RadRichtTextBox is created:

A first chance exception of type 'Telerik.Windows.Documents.FormatProviders.Rtf.Exceptions.RtfEmptyDocumentException' occurred in Telerik.Windows.Documents.FormatProviders.Rtf.dll

What do I wrong? With the Microsoft RichTextbox I get no exception...

0
bernd kopp
Top achievements
Rank 1
answered on 02 Apr 2011, 12:03 PM
I have also tried your RadRichTextbox with your RadGridView:

<telerik:RadGridView>
                <telerik:RadGridView.Columns>
                    <telerik:GridViewColumn>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                   
 
                                    <telerik:RadRichTextBox Grid.Row="0" x:Name="RTFBox" />
                                    <telerikProvider:RtfDataProvider                                       
                                        Rtf="{Binding Content}"
                                        UpdateSourceTrigger="LostFocus"
                                        RichTextBox="{Binding ElementName=RTFBox}" />
                                </Grid>
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>


and I get the same error. Why can a Document not be empty?
0
bernd kopp
Top achievements
Rank 1
answered on 02 Apr 2011, 07:26 PM
I have set RowHeight to 200px but still the RichTextBox in the DataTemplate has a Height of probably 2000px I can scroll much because I have uch RTF Text loaded.

The binding now works to my ViewModel, but the RowHeight is totally ignored, what do I wrong?

<telerik:RadGridView 
                ItemsSource="{Binding PeriodListViewModel,IsAsync=True}"
                AutoGenerateColumns="False"
                RowHeight="200"                
                >
                <telerik:RadGridView.Columns>                    
                    <telerik:GridViewColumn Header="Homework">
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox Width="100" Grid.Row="0"
                                        TextWrapping="Wrap"
                                        ScrollViewer.VerticalScrollBarVisibility="Auto"
                                        Text="{Binding Path=Homework,UpdateSourceTrigger=LostFocus}"
                                        />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewColumn Header="Content" Width="200">
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>  
                                    <telerik:RadRichTextBox Grid.Row="0" x:Name="RTFBox" />  
                                    <telerikProvider:RtfDataProvider                                       
                                        Rtf="{Binding Content}"
                                        UpdateSourceTrigger="LostFocus"
                                        RichTextBox="{Binding ElementName=RTFBox}" />
                                </Grid>
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView> 
0
Rieni De Rijke
Top achievements
Rank 1
answered on 03 Apr 2011, 08:02 PM
I think it's still very difficult to get the binding to work.
Could you please consider to provide a simple example in wpf. Maybe with a table?

And...
Say I have this text in a textbox:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">

.p_CC664AAA { margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; } 
.s_E6FD2046 { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; } 
</style></head><body><p class="p_CC664AAA"><span class="s_E6FD2046">hello</span></p></body></html>

Now I want to show the text ("hello") in my RichTextBox Document.

I tried to bind/copy it to a HtmlDataprovider and rebind this to the RadRichTextBox. But everytime my Document just dissapears. 
0
Iva Toteva
Telerik team
answered on 07 Apr 2011, 08:58 AM
Hello Rieni De Rijke,

Please find attached a sample demo of the use of data providers in the WPF RadRichTextBox.
The RibbonBar at the top is bound to the first RichTextBox, whose document is bound to the view model. The two RichTextBoxes at the bottom are bound to one another.
I hope this helps.

Greetings,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rieni De Rijke
Top achievements
Rank 1
answered on 07 Apr 2011, 10:15 PM
Thank you for your answer.
I wrote:

"...Now I want to show the text ("hello") in my RichTextBox Document.

I tried to bind/copy it to a HtmlDataprovider and rebind this to the RadRichTextBox. But everytime my Document just dissapears. "

In your sample, there is no Document. The text seems to lay direct on the RichTextBox.

I thought it would be possible to open a new document and fill it up with text/html from a datarow or object.
When I try this, the document dissapears.

            _radDocument = new RadDocument
            {
                LayoutMode = DocumentLayoutMode.Paged,
                ParagraphDefaultSpacingAfter = 10,
                PageViewMargin = new SizeF(10, 10),
                SectionDefaultPageMargin = new Padding(95)
            };
            editor.Document = _radDocument;
And now fill it up with content from a datarow or object.

0
Accepted
Iva Toteva
Telerik team
answered on 13 Apr 2011, 01:29 PM
Hi Rieni De Rijke,

I am sorry for not making myself clear on the behavior of the rich text box and the data providers.
RadRichTextBox has a Document property that is of type RadDocument. There is no other way to show anything in the rich text box, but to put it in a RadDocument and assign that document to the Document property of the rich text box. When you declare a RadRichTextBox in XAML and run the application, an instance of RadDocument is automatically created for you and placed inside the rich text box. When you invoke methods of the rich text box that change the contents of the document (Insert(), methods for changing the formatting, etc.), these manipulations are performed on its document.
The format providers are able to create documents from strings/Streams that specify content in specific format. The data providers, built on top of some format providers, bind the contents of the document in the rich text box to strings in XAML, RTF, HTML or plain text format. In order to update the string property they are bound to, they use the corresponding format provider to export the document inside the rich text box. On the other hand, when they have to update the document, they import the string and create a new document, which gets assigned to the Document property of the rich text box. This is done, so that you don't need to manually create a document and fill it up with the data from data rows and other objects.
If you plan to create the documents manually, you should not use data-binding but simply assign the document property like you did in the code-snippet.

All the best,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Brian Stanek
Top achievements
Rank 2
answered on 05 Feb 2014, 08:41 PM
Ok, now I am extremely confused and I have not found a simple WPF RadRichBox sample anywhere.  It seems that the writers for the ASP.NET AJAX samples should be giving lessons to the writes of WPF.  A getting started sample should show the minimum and provide a way to get started, not have 40 lines of ribbon code and one line of a RadRichBox that shows nothing.

This is what I want to do:
1) I read HTML data from the database
2) I want the user to edit the HTML data in an WPF user control that is using MVVM.

I admit I am a lot better in ASP.NET AJAX than WPF. But I would think that your documentation would not assume a complete understanding of WPF and would provide starting level examples.  On the ASP.NET AJAX demos/samples/documentation, I can get answers to these simple questions and then add features as I find them necessary for my project.

So I want to use this in my XAML:

<Label Name="lblMessage" Content="Message:" Grid.Row="2" Grid.Column="0" />
<telerik:RadRichTextBox Name="txtMessage" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" >
</telerik:RadRichTextBox>

Notice, no formatting options, no ribbon bars, etc.  I want to get it to work before I add more features.


And then I want to do this in my View Model:

String _message;
public String Message
{
    get
    {
        return this._message;
    }
    set
    {
        this._message = value;
        this.NotifyPropertyChange("Message");
    }
}

How do I link these two together?  The content of message is either blank or something like this:
"The next Staff Meeting is on Friday, 11/22/2013 at 10:30am. There will be updates on:<br/>*&nbsp;3rd quarter results<br/>*&nbsp;Fronting<br/>*&nbsp;Reinsurance<br/>*&nbsp;2014 Goals<br/>*&nbsp;and Anything else that is important to the group"

When the user changes the value, I want the property updated and able to be sent to the database.

Another quick comment on your documentation, I spent 2 hours trying to find out how to do a simple non-data bound combo box.  I find out that it is best not to use your site for examples and that is painful to me.  I recommend your ASP.NET AJAX examples to peers and right now, I cannot on your WPF documentation or examples.
0
Missing User
answered on 06 Feb 2014, 01:26 PM
Hi Brian,

Thank you for contacting us!

I am sorry to see your disappointment of our documentation, but I can assure you that we try to include everything you need to accomplish your desired scenario in it. We are open to all kind of feedback. If you feel that there is a place for improvement in a given article/s the way you want to see it please drop us a line.

The getting started article for RadRichTextBox shows a simple use of the control, so we are not sure which is the resource you are referring to. In general, as the control comes with a lot of predefined UI we try to include such examples as well, but one basic scenario is demonstrated here. RadComboBox's getting started article shows how the control can be used with static items as well, so we'd appreciate your feedback regarding what more you'd like to see.

To the question at hand, RadRichTextBox not only gives you the ability to display rich text content, but also helps you to import/export the same from/to different file formats. This’s why Data providers were created. A clear example of this is using RIA Services and the MVVM model for creating applications. You can decide which rich text providers is the best to your binding data. Please take a look at this article for a reference.

If your binding data is in HTML, you should use the HtmlDataProvider. We have a SDK example which illustrates how this could be achieved with XamlDataProvider. The SDK examples are also accessible through the SDK browser and are another good developer-oriented online tool.

I hope this helps!
If you have any further questions or additional feedback, do not hesitate to contact us.

Regards,
Yancho
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Rieni De Rijke
Top achievements
Rank 1
Answers by
bernd kopp
Top achievements
Rank 1
Iva Toteva
Telerik team
Rieni De Rijke
Top achievements
Rank 1
Brian Stanek
Top achievements
Rank 2
Missing User
Share this question
or