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
Regards
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:
Best wishes,
Alex
the Telerik team
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.
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
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.
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
Kind regards,
Ivailo
the Telerik team
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 ?
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
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
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,
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.