1

有什么方法可以访问导入的 XAP 文件的 app.xaml 资源(来自主机 silverlight 应用程序)???

或者更好的是,将访客 app.xaml 导入主机 app.xaml

问题是在导入的 Silverlight 应用程序中,我丢失了所有 app.xaml 资源,我只看到主机资源......我想合并它们......

这是可能的?

我以这种方式加载 XAP

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);
}
4

1 回答 1

0

如果您知道资源文件的 uri,例如:“/ COMPONENTNAME ;component/ resourcepath .xaml”,

您可以通过编写如下代码简单地将这个资源字典添加到您的应用程序中: Application.Current.Resources.MergedDictionaries.Add("*resourceuri*");

“Application.Current”始终指向运行时应用程序实例(宿主应用程序),无论它在哪里使用。

于 2014-06-30T07:08:34.570 回答