簡體   English   中英

Silverlight從動態XAP加載導入App.xaml

[英]Silverlight import App.xaml from dynamically xap loaded

有什么方法(從主機silverlight應用程序)訪問導入的XAP文件的app.xaml資源?

或者更好的是,將來賓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);
}

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

您只需編寫以下代碼即可將此資源字典添加到您的應用程序中: Application.Current.Resources.MergedDictionaries.Add("*resourceuri*");

無論在何處使用,“ Application.Current”始終指向運行時應用程序實例(主機應用程序)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM