开发者

Silverlight RichTextBox: How to set custom font from resource/stream?

Does anybody know how to set the font within a RichTextBo开发者_StackOverflow中文版x from a Stream?

TextBlock and TextBox do have the option to set the FontSource, but classes like Run, Paragraph and the whole RichTextBox miss that. :( Any reason for that?

Is there any known way to achieve that? I already tried to set the whole source URI within the FontFamily but that does not seem to work on external sources, just for internal URI addresses like /SilverlightFontTest;component/GRAFFITO_01.ttf#Graffito.

I cannot find any further information what to try next or how to go on, please help me.

Kind Regards,

Bastian


You can specify a custom font in a Silverlight control but if it isn't installed on the user's machine, it must be stored in your project somewhere. I've done this by creating a "fonts" folder. You must also set each font file's "build action" to "resource" in the Properties window.

Then you can refer to these fonts in your code. In the silverlight richtextbox you can specify a FontFamily like this:

Dim oFontFamily as New FontFamily("fontFolderName/FontFileName.otf#FontName") myRichTextBox.Selection.ApplyPropertyValue(Run.FontFamilyPoeprty, oFontFamily)

So for Helvetica LT STD Roman, it would go like:

Dim oFontFamily as new FontFamily("fonts/HelveticaLTSTD-Roman.otf#Helvetica LT Std")

You can get the actual font name ("Helvetica LT Std") by manually opening the font file.

From the previous example, I've got my font files stored in a folder called "fonts" in my Silverlight project.

It's not the most straightforward solution, but it does work. Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜