On the client side we would have the Silverlight RTB. It would send its XAML to the server to be saved into the database.
Then from a service the XAML would be loaded into a in-memory WPF RTB and then an image of the content would be generated.
My Question is, can the WPF RTB be used in a service that does not have an interface? And if it can, Will I be able to create a RenderTargetBitmap of its visual?
5 Answers, 1 is accepted
You can use RadRichTextBox in a service, but you should set thread apartment state to STA:
Thread thread =
new
Thread(() =>
{
RadDocument document =
new
XamlFormatProvider().Import(xaml);
// do something
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
Don't hesitate to contact us if you have further questions.
Regards,Boby
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
This would only be used with short messages and the view window will be the "border" so there would be nothing beyond the view port.
Any chance I could get a working snippet for this functionality? Here is what I have been trying, which results in an empty png file of the correct dimensions.
private
const
string
RtfContent = @
"{\rtf1\ansi\uc1\pard Test \ul RTF\ulnone Text\par}"
;
static
void
Main(
string
[] args)
{
var thread =
new
Thread(() =>
{
var doc =
new
RtfFormatProvider().Import(RtfContent);
doc.MeasureAndArrangeInDefaultSize();
var width = doc.DesiredSize.Width;
var height = doc.DesiredSize.Height;
var vrtb =
new
RadRichTextBox { Document = doc, Width = width, Height = height};
vrtb.ApplyTemplate();
vrtb.Measure(
new
Size(width, height));
vrtb.Arrange(
new
Rect(0, 0, width, height));
vrtb.UpdateLayout();
var renderTargetBitmap =
new
RenderTargetBitmap((
int
)width, (
int
)height, 96, 96, PixelFormats.Pbgra32);
renderTargetBitmap.Render(vrtb);
var encoder =
new
PngBitmapEncoder();
using
(var fs =
new
FileStream(@
"C:\Temp\test.png"
, FileMode.Create))
{
encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
encoder.Save(fs);
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
Thank You.
It is not possible to take a snapshot of RadRichTextBox on the server. RadRichTextBox has to be added to the visual tree in order to create a bitmap out of it. This may be the behavior of BitmapSource by design, as the same code does not work for a TextBox either.
The functionality that is available on the server is to import a document from any of the supported file formats, modify it programmatically and export it. What you can do is to create the images on the client (in the Silverlight project) and only then send it to the server.
I hope this answers your question.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
David