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

Problem with Q2

10 Answers 297 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Meerkat
Top achievements
Rank 1
Meerkat asked on 14 Jul 2010, 07:02 PM

Hello,
I have just downloaded the latest Q2 version and I am having one or two problems whichI am am hoping you wil be able to help me with.
Firstly I cannot run the demo project

Copy and paste of Errors - not very well formatted but should be enough to point out what is wrong.

Error 4 The type or namespace name 'XapDownloadEventArgs' could not be found (are you missing a using directive or an assembly reference?) C:\Program Files\Telerik\RadControls for Silverlight Q2 2010\Demos\QuickStart\Controls\ExampleContentControl.cs 239 43 QuickStart_SL
Error 5 The type or namespace name 'XapDownloadEventArgs' could not be found (are you missing a using directive or an assembly reference?) C:\Program Files\Telerik\RadControls for Silverlight Q2 2010\Demos\Examples.Silverlight\Default.xaml.cs 54 43 Examples.Silverlight
Error 3 The command "Copy "C:\Program Files\Telerik\RadControls for Silverlight Q2 2010\Demos\QuickStartLoader\Bin\Debug\Telerik.Windows.QuickStartLoader.dll" "C:\Program Files\Telerik\RadControls for Silverlight Q2 2010\Demos\..\Binaries\Silverlight"" exited with code 1. QuickStartLoader_SL

Secondly the following code was broken. Perhaps there is a better way of reading strings now, but the documentation does not seem to have changed for the latest version.

using Telerik.Windows.Documents.FormatProviders.OpenXml.Docx;
using Telerik.Windows.Documents.FormatProviders.Xaml;
using Telerik.Windows.Documents.FormatProviders.Html;
using Telerik.Windows.Documents.FormatProviders;
using Telerik.Windows.Documents.Selection;
using System.IO;
  
namespace Rubbish
{
  public partial class ProfileTabTelerik : UserControl
  {
  
    public string ExportToXAML(RadDocument document)
    {
      IDocumentFormatProvider provider = new XamlFormatProvider();
      string exportValue = String.Empty;
      using (MemoryStream output = new MemoryStream())
      {
        provider.Export(document, output);
        output.Seek(0, SeekOrigin.Begin);
        using (StreamReader reader = new StreamReader(output))
        {
          exportValue = reader.ReadToEnd();
        }
      }
      return exportValue;
    }
  
    public RadDocument ImportXaml(string content)
    {
      IDocumentFormatProvider provider = new XamlFormatProvider();
      RadDocument document;
      using (MemoryStream stream = new MemoryStream())
      {
        StreamWriter writer = new StreamWriter(stream);
        writer.Write(content);
        writer.Flush();
        stream.Seek(0, SeekOrigin.Begin);
        document = provider.Import(stream);
      }
      return document;
    }


Many thanks in anticipation.

10 Answers, 1 is accepted

Sort by
0
joe lee
Top achievements
Rank 1
answered on 16 Jul 2010, 12:59 AM
I have the same problems. Where are the HtmlFormatProvider and XamlFormatProvider?

Regards

Joe Lee
0
Alex
Telerik team
answered on 16 Jul 2010, 10:39 AM
Hello Joe Lee,

For the official Q2 release we moved FormatProviders to separate assemblies. This way you can include in your application only the providers you need. Here is the list of the format providers and the assemblies they in which they are defined:

HtmlFormatProvider - TelerikWindows.Documents.FormatProviders.Html
DocxFormatProvider - TelerikWindows.Documents.FormatProviders.OpenXml
XamlFormatProvider - TelerikWindows.Documents.FormatProviders.Xaml
TxtFormatProvider - Telerik.Windows.Documents.dll

@Pete Davies:

Currently the Import/Export methods of the format providers work only with streams, so you will have to use MemoryStream and StreamReader to get the string values. For the next service pack we will extend the API of the providers with Import and Export methods that will work directly with strings.

Best wishes,
Alex
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
Meerkat
Top achievements
Rank 1
answered on 16 Jul 2010, 11:55 AM
Hello Alex,
Perhaps I did not pose my question correclty. I was trying to find out what I needed to do to get the current code to work with the latest Q2 version. I am sure Joe Lee now knows exactly what to do but I am afraid I don't. Please could you assume that I am a complete idiot and tell me exactly what I need to do. In other words, how do I implement the advice you gave to Joe Lee.
Many thanks.
0
Mike
Telerik team
answered on 19 Jul 2010, 01:52 PM
Hello Pete Davies,

The code you provided should work just fine with Q2 version, all you need to do is to add references to the following assembly in your application:

TelerikWindows.Documents.FormatProviders.Xaml

where the XamlFormatProvider is now located.

All the best,
Mike
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
Ludovic Gerbault
Top achievements
Rank 1
answered on 20 Aug 2010, 02:31 PM
Hello

In Q2 SP1, the assembly Telerik.Windows.Document.FormatProviders only contains Html and Txt

Did you remove the XamlFormatProvider from there, I can't find it anywhere.
0
Ivailo Karamanolev
Telerik team
answered on 23 Aug 2010, 08:03 AM
Hi Subileau Pascal,

Since the initial official release (2010 Q2), we have been distributing the format providers using this model:
  • TxtFormatProvider is shipped inside the main assembly: Telerik.Windows.Documents.dll
  • HtmlFormatProvider is shipped with a separate assembly: Telerik.Windows.Documents.FormatProviders.Html.dll
  • XamlFormatProvider is inside Telerik.Windows.Documents.FormatProviders.Xaml.dll
  • DocxFormatProvider is inside Telerik.Windows.Documents.FormatProviders.OpenXml.dll
There is also a Telerik.Windows.Documents.FormatProviders.Html namespace inside the main assembly, but that is since the printing functionality, which is in Telerik.Windows.Documents.dll uses HTML internally. The actual format provider is inside a separate assembly as outlined above.

Kind regards,
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
Ludovic Gerbault
Top achievements
Rank 1
answered on 23 Aug 2010, 09:09 AM
Thanks

But there are some other pieces of code that I can't get to work.

For instance, the CompositeCommandContext seems to have disappear.

I also can't adapt this particular code

if (inlineBox.AssociatedInline is Span)
               {
                    
                   Span span = (Span)inlineBox.AssociatedInline;
                   DocumentPosition start = new DocumentPosition(this.editor.Document.CaretPosition, false);
                   DocumentPosition end = new DocumentPosition(this.editor.Document.CaretPosition, false);
 
                   Hyperlink link = new Hyperlink();
                   link.CopyPropertiesFromStyle(span);
 
                   if (!string.IsNullOrEmpty(link.URL))
                   {
                       select the whole hyperlink span
                       InlineLayoutBox lastBox = (InlineLayoutBox)span.GetAssociatedLayoutBoxes().Last();
                        
                       start.UpdatePositionHandlerStack((InlineLayoutBox)span.FirstLayoutBox, 0, null);
                       end.UpdatePositionHandlerStack(lastBox, lastBox.PositionsCountInBox, null);
 
                       this.txtAdress.Text = link.URL;
 
                       this.UpdateSlectionAndCaret(start, end);
                   }
                   else if (!inlineBox.IsFormattingSymbol)
                   {
                       select word
                       SpanLayoutBox startbox = DocumentStructureCollection.FindFirstBoxForWord((SpanLayoutBox)inlineBox);
                       SpanLayoutBox endBox = DocumentStructureCollection.FindLastBoxForWord((SpanLayoutBox)inlineBox);
                        
                       start.UpdatePositionHandlerStack(startbox, 0, null);
                       end.UpdatePositionHandlerStack(endBox, endBox.PositionsCountInBox, null);
 
                       this.UpdateSlectionAndCaret(start, end);
                   }
                   this.txtText.Text = editor.Document.Selection.GetSelectedText();
               }

Can you help me with that ?
0
Mike
Telerik team
answered on 25 Aug 2010, 03:48 PM
Hi Subileau Pascal,

My best guess is that the code you provided should (mainly)  select a whole hyperlink or word under the caret. I've modified the code accordingly to make it work again, please find an application attached that demonstrates it built with latest version of RadRichTextBox (Q2 SP1).
Here is the converted snippet:
private void button1_Click(object sender, RoutedEventArgs e)
{
    var inlineBox = this.editor.Document.CaretPosition.GetCurrentInlineBox();
 
    if (inlineBox.AssociatedInline is Span)
    {
        Span span = (Span)inlineBox.AssociatedInline;
        DocumentPosition start = new DocumentPosition(this.editor.Document.CaretPosition, false);
        DocumentPosition end = new DocumentPosition(this.editor.Document.CaretPosition, false);
 
        Hyperlink link = new Hyperlink();
        link.CopyPropertiesFrom(span);
 
        if (!string.IsNullOrEmpty(link.URL))
        {
            //select the whole hyperlink span
            InlineLayoutBox lastBox = (InlineLayoutBox)span.GetAssociatedLayoutBoxes().Last();
 
            start.MoveToInline((InlineLayoutBox)span.FirstLayoutBox, 0);
            end.MoveToInline(lastBox, lastBox.PositionsCountInBox);
 
            //this.txtAdress.Text = link.URL;
 
            this.UpdateSlectionAndCaret(start, end);
        }
        else if (!inlineBox.IsFormattingSymbol)
        {
            //select word
            //Fixed original approach:
            //SpanLayoutBox startbox = DocumentStructureCollection.FindFirstBoxForWord((SpanLayoutBox)inlineBox);
            //SpanLayoutBox endBox = DocumentStructureCollection.FindLastBoxForWord((SpanLayoutBox)inlineBox);
 
            //start.MoveToInline(startbox, 0);
            //end.MoveToInline(endBox, endBox.PositionsCountInBox);
 
            //Recommended approach:
            start = new DocumentPosition(this.editor.Document);
            start.MoveToInline(inlineBox, 0);
            end = new DocumentPosition(start);
            end.MoveToCurrentWordEnd();
 
            this.UpdateSlectionAndCaret(start, end);
        }
 
        //this.txtText.Text = editor.Document.Selection.GetSelectedText();
    }
 
    //return the focus back to the editor
    this.editor.ActiveEditorPresenter.FocusCaret();
}

Let me know how it goes.

Best wishes,
Mike
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
Azadeh
Top achievements
Rank 1
answered on 13 Aug 2012, 07:20 AM
Hi Mike,
I'm beginner in SilverLight and i download your attach for RadRichTextbox Samples.
but after run it does nothing and alseo show Wait icon.
can u help me?
thanks,
Azadeh
0
Petya
Telerik team
answered on 15 Aug 2012, 03:39 PM
Hello Azadeh,

I assume you are trying to implement a way to select a whole hyperlink or word under the caret.

Since Hyperlink is depricated I modified the project Mike previously attached to use HyperlinkRangeStart. You can read more about the new hyperlinks in this article. The sample project is for Silverlight 4 and uses the 2012 Q2 SP1 version of the controls. 

Please, try it and if your issues persist, get back to us. 

All the best,

Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Meerkat
Top achievements
Rank 1
Answers by
joe lee
Top achievements
Rank 1
Alex
Telerik team
Meerkat
Top achievements
Rank 1
Mike
Telerik team
Ludovic Gerbault
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Azadeh
Top achievements
Rank 1
Petya
Telerik team
Share this question
or