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

RichTextBox as DataForm field

3 Answers 94 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Gabe
Top achievements
Rank 1
Gabe asked on 19 Dec 2011, 10:15 PM
I'm trying to create a DataForm that uses a RichTextBox as one of the entry fields. My problem comes in when I try to programmatically set the binding of the RichTextBox. Here's what I have:

private void editCabinetForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
        {
            if (e.PropertyName == "CabinetName")
            {
                e.DataField.Label = "Cabinet Name";
            }
            else if (e.PropertyName == "BriefDescription")
            {
                e.DataField.Label = "Brief Description";
            }
            else if (e.PropertyName == "Comments")
            {
                RadRichTextBox commentsBox = new RadRichTextBox();
                //commentsBox.SetBinding(???, new Binding("Comments"));
                e.DataField.Content = commentsBox;
                e.DataField.Label = "Comments";
            }
            else
            {
                e.Cancel = true;
            }
        }

(Comments is a string variable)

I'm not quite sure what to use for the dependency property - any suggestions?

3 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 22 Dec 2011, 12:35 PM
Hello Gabe Burch,
You can use one of our data providers, depending on the format you use for storage. Generally, if there is no other special requirements,  we recommend usage of our internal Xaml format:
if (e.PropertyName == "Comments")
{
    Grid grid = new Grid();
 
    XamlDataProvider provider = new XamlDataProvider();
    grid.Children.Add(provider);
 
    RadRichTextBox commentsBox = new RadRichTextBox();
    grid.Children.Add(commentsBox);
 
    provider.SetBinding(XamlDataProvider.XamlProperty, new Binding("Comments") { Mode = BindingMode.TwoWay });
    provider.RichTextBox = commentsBox;
 
    e.DataField.Content = grid;
    e.DataField.Label = "Comments";
}

Don't hesitate to contact us if you have other questions.

Regards,
Boby
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Gabe
Top achievements
Rank 1
answered on 22 Dec 2011, 06:55 PM
I ended up using FormatProviders.Rtf but everything worked great.

I would also like the RichTextBox to fill the available space in the DataForm, what would be the easiest way to go about this?
0
Vanya Pavlova
Telerik team
answered on 26 Dec 2011, 11:31 AM
Hi Gabe,



You may try to utilize the approach demonstrated in the following thread "How to stretch content within DataForm". I believe that the same is applicable to WPF as well. 
Will you verify how this works for you? 



All the best,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Gabe
Top achievements
Rank 1
Answers by
Boby
Telerik team
Gabe
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or