Is there any way to access app.xaml resources of an imported XA开发者_如何学PythonP file (from host silverlight app) ???
Or better, import guest app.xaml into Host app.xaml
Problem is that in the imported Silverlight application, I lost all app.xaml resources, and I just see host resources... I would like to merge them...
It's possible?
I load XAP in this way
private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var manifestStream = Application.GetResourceStream(
new StreamResourceInfo(e.Result, null),
new Uri("AppManifest.xaml", UriKind.Relative));
string appManifest = new StreamReader(manifestStream.Stream).ReadToEnd();
string assemblyName =m_rootAssembly + ".dll";
XmlReader reader = XmlReader.Create(new StringReader(appManifest));
Assembly asm = null;
while (reader.Read())
{
if (reader.IsStartElement("AssemblyPart"))
{
reader.MoveToAttribute("Source");
reader.ReadAttributeValue();
if (reader.Value == assemblyName)
{
var assemblyStream = new StreamResourceInfo(e.Result, "application/binary");
var si = Application.GetResourceStream(assemblyStream, new Uri(reader.Value, UriKind.Relative));
AssemblyPart p = new AssemblyPart();
asm = p.Load(si.Stream);
break;
}
}
}
if (asm == null)
throw new InvalidOperationException("Could not find specified assembly.");
var o = asm.CreateInstance(m_typeName);
if (o == null)
throw new InvalidOperationException("Could not create instance of requested type.");
RaiseXapLoadedEvent(o);
}
if you know the uri of the resource file, like: "/COMPONENTNAME;component/resourcepath.xaml",
you can simply add this resource dictionary to your application by writing codes like:
Application.Current.Resources.MergedDictionaries.Add("*resourceuri*");
the "Application.Current" always points to the runtime application instance (host application), no matter where it is used.
精彩评论