views:

33

answers:

1

Hi there,

I do load an assembly on demand which holds ressources (fonts) in it. The assembly is being loaded by the AssemblyPart class, and therefore added to the current application domain.

txt1.FontFamily = New FontFamily("/SilverlightFontLibrary;component/GRAFFITO_01.ttf#Graffito")

Dim kaa = Application.GetResourceStream("/SilverlightFontLibrary;component/GRAFFITO_01.ttf".ToUri(UriKind.Relative))

The font is not being applied to the text, but I do get the ressource stream.

If the assembly is inside the xap package everything works fine, but setting it to copy local false it won't show the correct font. :(

I cannot use the FontSource to set the font directly as stream (which I definately have), because classes like Run, Paragraph or the RichTextBox simply do not have them. ;(

Does anybody know whether MEF (Microsoft Extensibility Framework) can help me out of this?

Is there any known way to accomplish that?

I seriously need to refer to those ressources, but cannot put them all into one xap package. :(

Kind regards

A: 

Consider de-coupling your main project's dependency on knowing the full url to the font. Instead create an IFontProvider interface in a third project referenced by both your other projects (apologies for C# I don't do VB.NET) :-

 public interface IFontProvider
 {
   FontFamily this[string name] {get; }
 } 

In your font library create an implementation of this:-

public class FontProvider : IFontProvider
{
  public FontFamily this[string name]
  {
     get
     {
        switch (name)
        {
            case "Graffito": 
              return New FontFamily("/SilverlightFontLibrary;component/GRAFFITO_01.ttf#Graffito");
            default:
             return null;
        }
     }   
}

With the library assembly loaded into the domain you should be able to access a font:-

Type providerType = Type.GetType("SilverlightFontLibrary.FontProvider, SilverlightFontLibrary");
IFontProvider fonts = Activator.CreateInstance(providerType) As IFontProvider;
txt1.FontFamily = fonts["Graffito"];

With the "component" url being used from code within the same component it should be able to find the resource.

There are some blogs on MEF and Dynamic assembly loading so you may be able to use it dynamically wire up a field of type IFontProvider with the library implementation.

AnthonyWJones
Hi Anthony,I tried it your way, but unfortunately it is the same result.The font is still not applied.Thank you for posting that idea. :)
Haragashi