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

How to bind the data when richtext box is placed in datatemplate

3 Answers 240 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Naveen T
Top achievements
Rank 1
Naveen T asked on 03 Sep 2010, 03:44 PM
Hi,

I tried to bind rich textbox which present in datatemplate.I'm able to bind(using the example given in this  forum http://www.telerik.com/community/forums/silverlight/richtextbox/how-do-you-bind-richtextbox.aspx ) but i am getting few errors when i do the following the things
1. In the initial binding,Am getting "Layout cycle detected.  Layout could not complete." in the Html changed method at

control.radRichTextBox.UpdateEditorLayout()


2. After this i removed the error line and tried to bind the data(set the richtextbox in readonly mode),its binding correctly,but when i  doubleclick on the richtext box i am getting webpage error dialogbox saying  Unhandled Error in Silverlight Application
Code: 4008   
Category: RuntimeError      
Message: Layout cycle detected.  Layout could not complete.    
MethodName:     

3. Then i removed Readonly mode option,after binding  I doubleclick on the richtext box previous error occurs.

The other issue is when ever i am binding the richtextbox,the text inside it is taking so much margin even though i set zero margin and other settings in control load but i getting differently when binding the data,please see the image i attached

sample data :   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " xmlns=" http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">
.p_2F83C0B6 { margin: 0px 0px 12px 0px;text-align: lefttext-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_D8D99854 { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;background-color: #FFFFFE; }
</style></head><body><p class="p_2F83C0B6"><span class="s_D8D99854">test</span></p></body></html>



3 Answers, 1 is accepted

Sort by
0
Ivailo Karamanolev
Telerik team
answered on 03 Sep 2010, 04:10 PM
Hello nav kum,

Since Q2 SP1, we have introduced a few additional classes to aid databinding and avoid the need to create custom controls. You can find more on the topic over here; you'll be interested in using HtmlDataProvider. Also, in this article is described how to attach to an event that allows you to customize a document after it's imported but before it's shown. Please have a look at the data providers and if your problems persist after you migrate to HtmlDataProvider, contact us with a demo solution which shows your problems, so we can assist you further.

All the best,
Ivailo
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
Naveen T
Top achievements
Rank 1
answered on 03 Sep 2010, 04:54 PM
Hi,
 
I have used the Html providers, unable to display the data,displaying control with no text
below is the sample which i had defined in pages,I am getting data from DB and binding them to the below controls
and please reply solution for why control is displaying data with much margin when binding(see the image i attached) 

Design page:

<UserControl xmlns:my2="clr-namespace:AMB.SOS.Client.Controls.CommonControls"
             xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit" 
             xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
             xmlns:sdkg="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
             x:Class="AMB.SOS.Client.Controls.EditTicket"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
   xmlns:common="clr-namespace:AMB.SOS.Client.Common;assembly=AMB.SOS.Client.Common"
   xmlns:Treectrl="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
   xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
    xmlns:sdkgrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
   xmlns:sdk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"
   xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
              xmlns:Htmlprovider="clr-namespace:Telerik.Windows.Documents.FormatProviders.Html;assembly=Telerik.Windows.Documents.FormatProviders.Html"
   xmlns:my1="clr-namespace:AMB.SOS.Client.Controls"
    >
             
<UserControl.Resources>
       
        <Htmlprovider:HtmlDataProvider x:Key="htmlprovider" RichTextBox="{Binding ElementName=ctrlCommentsrichTextBox}"
                                       Html="{Binding ElementName=txtblkcommentDescformattag, Path=Text,Mode=TwoWay}"    />
    </UserControl.Resources>
      

    <Grid x:Name="LayoutRoot"  >
 
                        <Treectrl:TreeView ItemsSource="{Binding Path=Auditcomments}" x:Name="trvComments" Height="Auto" Width="Auto"  HorizontalAlignment="Left" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"  VerticalAlignment="Top" >
                            <Treectrl:TreeView.ItemTemplate>
                                <Treectrl:HierarchicalDataTemplate
                                   ItemsSource="{Binding Path=AuditComments1}" >
                                   <telerik:RadRichTextBox Margin="5" Width="300" HorizontalAlignment="Left" x:Name="ctrlCommentsrichTextBox"  />
          
                <TextBox Height="25" Width="50" x:Name="txtblkcommentDescformattag"  Visibility="Collapsed" Text="{Binding Path=Comments,Mode=TwoWay}" />
                                </Treectrl:HierarchicalDataTemplate>
                            </Treectrl:TreeView.ItemTemplate>
                           

                        </Treectrl:TreeView>                   
           
     

    </Grid>
</UserControl>


CS page contains:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AMB.SOS.Client.Controls.ChildControls;
using AMB.SOS.Client.Common;
using AMB.SOS.Server.DataServices;
using System.ComponentModel.Composition;
using AMB.SOS.Client.ViewModel;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System.IO;
using Telerik.Windows.Controls;

namespace AMB.SOS.Client.Controls
{
    public partial class EditTicket : UserControl,ICleanup
    {
       
        public EditTicket()
        {
            InitializeComponent();
            if (!GalaSoft.MvvmLight.ViewModelBase.IsInDesignModeStatic)
            {
                try
                {
                    // Use MEF To load the View Model
                    CompositionInitializer.SatisfyImports(this);
                }
                catch (Exception ex)
                {
                }
            }
          
        }
        [Import(ViewModelTypes.EditTicketViewModel)]
        public object ViewModel
        {
            set
            {
                DataContext = value;
            }
        }

       

       
       

      

       
    }
}

sample data for binding:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " xmlns=" http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled</title><style type="text/css">
.p_2F83C0B6 { margin: 0px 0px 12px 0px;text-align: lefttext-indent: 0pt;padding: 0px 0px 0px 0px; }
.s_D8D99854 { font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;background-color: #FFFFFE; }
</style></head><body><p class="p_2F83C0B6"><span class="s_D8D99854">test</span></p></body></html>



Regards,
Nav


 

0
Boby
Telerik team
answered on 08 Sep 2010, 03:54 PM
Hi nav kum,
In the Q2 SP1 version the when importing form HTML the created document is in flow mode and with the default values for page margins(95 pixels). You can alter these margins trough the SectionDefaultPageMargin property of the document. However, page margins should not be shown at all when the document is in flow layout mode - this is already so in Latest Internal Build (LIB). So if you want to get rid of the margins you have two options: either change the SectionDefaultPageMargin manually after the document is imported or try using the LIB version (you can find it in the Downloads section in your profile).

I also noticed that there is small mistake in sample HTML, in the fragment:
text-align: lefttext-indent: 0pt;
This must be replace with:
text-align: left; text-indent: 0pt;
I suppose this HTML was generated by the Q2 SP1 version of HtmlFormatProvider; this incorrect behavior is fixed in LIB too.

Data providers work as expected with the provided sample HTML, so I believe the problem with not displaying data is caused by incorrectly set bindings in your code. You can refer to the following post to get an idea how data providers can be used inside DataTemplate: RichTextBox in RadGridView. (Basically, you have to move HtmlDataProvider in the resources of RadRichTextBox, inside the HierarchicalDataTemplate).

Please let us know if you have any other questions.

Kind regards,
Boby
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
Tags
RichTextBox
Asked by
Naveen T
Top achievements
Rank 1
Answers by
Ivailo Karamanolev
Telerik team
Naveen T
Top achievements
Rank 1
Boby
Telerik team
Share this question
or