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

Copying from TFS PBI

12 Answers 83 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 09 Apr 2014, 01:22 PM
Hi,
Copying from a TFS PBI Description into a rad Rich Text Box does not work.
Could this be due to different rich text formats and is there a way to fix this ?
Thanks
- Chris

12 Answers, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 14 Apr 2014, 10:54 AM
Hello Chris,

 I couldn't reproduce the described behavior. The text copied from TFS Product Backlog Item is pasted with no problems to RadRichTextBox.

Can you give us more information on how we can reproduce the issue. Like steps to reproduce and some screenshots.

Looking forward to your reply.

Regards,
Mihail
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
answered on 15 Apr 2014, 08:40 AM
Hi Mihail,
I am using a Rad rich text box in a Grid on a WPF form. It uses a HTML provider ... xaml as follows

 <Label Margin="2" Grid.Row="1" Content="Description"  />
                                    <telerikHTMLProvider:HtmlDataProvider x:Name="RtbDescriptionProvider" SetupDocument="RtbProvider_SetupDocument"
                                                                          RichTextBox="{Binding ElementName=RtbDescription}" 
                                                                          Html="{Binding Story.Description, Mode=TwoWay, Converter={StaticResource StringToHtmlConverter}}" />
                                    <telerik:RadRichTextBox x:Name="RtbDescription" 
                                                            AcceptsReturn="True"
                                                            Height="400"
    Margin="2"
                                                            Grid.Row="1"
                                                            Grid.Column="1"
                                                            Grid.ColumnSpan="3" 
                                                            IsSpellCheckingEnabled="True"
                                                            DocumentInheritsDefaultStyleSettings="True"
                                                            IsSelectionMiniToolBarEnabled="True"
                                                            IsContextMenuEnabled="True"
                                                            IsImageMiniToolBarEnabled="True"
                                                            IsSelectionEnabled="True"
                                                            FontFamily="Segoe UI" FontSize="12"
                                                            CommandExecuting="Paste_CommandExecuting"
                                                            HyperlinkClicked="Rtb_HyperlinkClicked"/>


The paste_CommandExecuting code is to remove any images or tables which are copied across, this does not get used as the message box doesn't display.


0
Mihail
Telerik team
answered on 16 Apr 2014, 11:27 AM
Hello Chris,

 I am still unable to reproduce the described issue. 
Could you confirm that the CommandExecuting event is triggered on paste command as this is the correct behavior.
Could you also provide the requested screenshots on the steps of reproducing the problem.

Looking forward to your reply.

Regards,
Mihail
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Chris
Top achievements
Rank 1
answered on 12 May 2014, 11:12 AM
Hi Mihail, really sorry for the late reply but here is how I handle the paste command and I can confirm that it is triggered in the xaml.cs. This is used to trim off tables / images from pasting (but neither of these message boxes are fired so it just passes it straight through)
With regards to the steps to reproduce - I have attached a screen shot but it is simply a issue with copying.

if (e.Command is PasteCommand)
            {
                bool messageBoxShown = false;
                DocumentFragment fragment = ClipboardEx.GetDocument();
                if (fragment != null)
                {
                    RadDocument document = fragment.ToDocument();
                    foreach (Telerik.Windows.Documents.Model.Block block in document.EnumerateChildrenOfType<Telerik.Windows.Documents.Model.Block>().ToList<Telerik.Windows.Documents.Model.Block>())
                    {
                        if (block is Telerik.Windows.Documents.Model.Paragraph)
                        {
                            (block as Telerik.Windows.Documents.Model.Paragraph).AutomaticSpacingBefore = false;
                            (block as Telerik.Windows.Documents.Model.Paragraph).AutomaticSpacingAfter = false;
                            (block as Telerik.Windows.Documents.Model.Paragraph).SpacingBefore = 0;
                            (block as Telerik.Windows.Documents.Model.Paragraph).SpacingAfter = 0;
                            
                            Telerik.Windows.Documents.Model.Paragraph para = block as Telerik.Windows.Documents.Model.Paragraph;

                            foreach (var item in para.Inlines)
                            {
                                if (item is ImageInline || item is FloatingImageBlock)
                                {
                                    para.Inlines.Remove(item);
                                    if (messageBoxShown == false)
                                    {

                                        MessageContoller messageController = ServiceLocator.Current.GetInstance<MessageContoller>();
                                        messageController.DisplayMessage(Strings.WarningMessage, Strings.CopyingImageOrTableWarning);
                                        messageBoxShown = true;
                                    }
                                }
                            }
                        }
                        else if (block is Telerik.Windows.Documents.Model.Table)
                        {
                            block.Parent.Children.Remove(block);
                            if (messageBoxShown == false)
                            {

                                MessageContoller messageController = ServiceLocator.Current.GetInstance<MessageContoller>();
                                messageController.DisplayMessage(Strings.WarningMessage, Strings.CopyingImageOrTableWarning);
                                messageBoxShown = true;
                            }
                        }
                    }
                    DocumentFragment newFragment = new DocumentFragment(document);
                    (sender as RadRichTextBox).InsertFragment(newFragment);
                    e.Cancel = true;
                }
                GC.Collect();
            }


0
Mihail
Telerik team
answered on 14 May 2014, 12:35 PM
Hello Chris,

 Thank you for the additional information.

I tested your code with visual studio 2010 and everything is working fine. The content in the description is copied correctly. What I found different is that on the provided screenshot you have options to set  font family and font size. Is that a plugin to the visual studio ? Could this be the problem ?
Could you try to get the content of the clipboard and check of everything is correctly there ?

Looking forward to your reply.

Regards,
Mihail
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Chris
Top achievements
Rank 1
answered on 14 May 2014, 01:06 PM
Hi,
I have checked through the content of the clipboard and it does appear to be there, the plugins I have are as follows:
0
Accepted
Mihail
Telerik team
answered on 19 May 2014, 11:07 AM
Hello Chris,

 Can you be so kind to try the following code which is attached to the CommandExecuting event of RadRichTextBox: 
void radRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        List<string> dataFormats = new List<string>();
        dataFormats.Add(DataFormats.Rtf);
        dataFormats.Add(DataFormats.UnicodeText);
 
        foreach (var dataFormat in dataFormats)
        {
            ClipboardHandler handler = ClipboardEx.ClipboardHandlers.Where(i => i.ClipboardDataFormat == dataFormat).FirstOrDefault();
            if (handler != null && handler.DocumentFormatProvider != null && handler.DocumentFormatProvider.CanImport)
            {
                string data = Clipboard.GetData(dataFormat) as string;
            }
        }
    }
}

And provide me content in the data variable for both formats, which is bold in the code snippet.

By default the ClipboardEx.ClipboardHandlers should contain three handlers: RTF, HTML and Text handlers.

Looking forward to your reply.

Regards,
Mihail
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Chris
Top achievements
Rank 1
answered on 19 May 2014, 11:34 AM
Hi Mihail,
so I have run this on my code, string data is not hit on rich text format because handler.documentformatprovider is null
it is hit on the unicodetext run through and pulls through the correct text.
0
Chris
Top achievements
Rank 1
answered on 19 May 2014, 01:54 PM
Hi Mihail, I have used the sample that you provided and edited it to work in my situation, I believe it was a problem from my TFS because the clipboardex.getdocument() was just returning null from a TFS PBI, below is my solution if anyone else is having the same issue ( bare in mind this removes formatting from TFS however that was not a big issue so long as the copy / paste works )

if (e.Command is PasteCommand)
            {
                
                bool messageBoxShown = false;
                DocumentFragment fragment = ClipboardEx.GetDocument();
                if (fragment != null)
                {
                    RadDocument document = fragment.ToDocument();
                    foreach (Telerik.Windows.Documents.Model.Block block in document.EnumerateChildrenOfType<Telerik.Windows.Documents.Model.Block>().ToList<Telerik.Windows.Documents.Model.Block>())
                    {
                        if (block is Telerik.Windows.Documents.Model.Paragraph)
                        {
                            (block as Telerik.Windows.Documents.Model.Paragraph).AutomaticSpacingBefore = false;
                            (block as Telerik.Windows.Documents.Model.Paragraph).AutomaticSpacingAfter = false;
                            (block as Telerik.Windows.Documents.Model.Paragraph).SpacingBefore = 0;
                            (block as Telerik.Windows.Documents.Model.Paragraph).SpacingAfter = 0;
                            
                            Telerik.Windows.Documents.Model.Paragraph para = block as Telerik.Windows.Documents.Model.Paragraph;

                            foreach (var item in para.Inlines)
                            {
                                if (item is ImageInline || item is FloatingImageBlock)
                                {
                                    para.Inlines.Remove(item);
                                    if (messageBoxShown == false)
                                    {

                                        MessageContoller messageController = ServiceLocator.Current.GetInstance<MessageContoller>();
                                        messageController.DisplayMessage(Strings.WarningMessage, Strings.CopyingImageOrTableWarning);
                                        messageBoxShown = true;
                                    }
                                }
                            }
                        }
                        else if (block is Telerik.Windows.Documents.Model.Table)
                        {
                            block.Parent.Children.Remove(block);
                            if (messageBoxShown == false)
                            {

                                MessageContoller messageController = ServiceLocator.Current.GetInstance<MessageContoller>();
                                messageController.DisplayMessage(Strings.WarningMessage, Strings.CopyingImageOrTableWarning);
                                messageBoxShown = true;
                            }
                        }
                    }
                    if (document.IsEmpty == true)
                    {
                        // possibly from tfs pbi 
                        // --- pasting from tfs - unicodeText format provides the actual text 

                        ClipboardHandler handler = ClipboardEx.ClipboardHandlers.Where(i => i.ClipboardDataFormat == DataFormats.UnicodeText).FirstOrDefault();
                        if (handler != null && handler.DocumentFormatProvider != null && handler.DocumentFormatProvider.CanImport)
                        {
                            string data = Clipboard.GetData(DataFormats.UnicodeText) as string;
                            (sender as RadRichTextBox).Insert(data);
                        }

                        //------

                    }
                    else
                    {
                        DocumentFragment newFragment = new DocumentFragment(document);
                        (sender as RadRichTextBox).InsertFragment(newFragment);
                    }
                    e.Cancel = true;
                }

0
Mihail
Telerik team
answered on 20 May 2014, 07:13 AM
Hello Chris,

 I am glad you managed to fix the issue. Nevertheless I am curious why the text is not imported by default.
Could you be so kind to test with the following code: 
if (e.Command is PasteCommand)
            {
                ClipboardHandler handler = ClipboardEx.ClipboardHandlers.Where(i => i.ClipboardDataFormat == DataFormats.UnicodeText).FirstOrDefault();
                if (handler != null && handler.DocumentFormatProvider != null && handler.DocumentFormatProvider.CanImport)
                {
                    string data = Clipboard.GetData(DataFormats.UnicodeText) as string;
 
                    using (MemoryStream stream = new MemoryStream())
                    {
                        StreamWriter writer = new StreamWriter(stream);
                        writer.Write(data);
                        writer.Flush();
                        stream.Seek(0, SeekOrigin.Begin);
                        try
                        {
                            var doc = handler.DocumentFormatProvider.Import(stream); // this is actually the TxtFormatProvider "var doc = new TxtFormatProvider().Import(data);"
                            DocumentFragment newFragment = new DocumentFragment(doc);
                            (sender as RadRichTextBox).InsertFragment(newFragment);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Error reading document from clipboard:\n" + ex.ToString());
                        }
                    }
                }
                e.Cancel = true;
            }


Looking forward to your reply.

Regards,
Mihail
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Chris
Top achievements
Rank 1
answered on 20 May 2014, 08:19 AM
Hi Mihail, this works as well, it seems to work when you are passing it as unicode text however it is not included in the ClipboardEx.getDocument();
Thanks again
-Chris
0
Mihail
Telerik team
answered on 21 May 2014, 10:58 AM
Hello Chris,

 Thank you for testing the sample code.

It is some how strange to me why the paste is not working by default as the code in my last post is responsible for the creation of the document fragment.
The main logic is to check if the clipboard has the data format of one of the clipboard handlers defined in the "ClipboardEx.ClipboardHandlers". Similar to this code: 
foreach (ClipboardHandler handler in ClipboardEx.ClipboardHandlers)
{
    var result = GetDocumentFromClipboard(handler.ClipboardDataFormat, handler.ClipboardStringFilter);
    return result;
}

Nevertheless I am glad that you managed to fix the issue. If you have further questions or comment feel free to contact us again.

Regards,
Mihail
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RichTextBox
Asked by
Chris
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Chris
Top achievements
Rank 1
Share this question
or