2011-09-14 10 views
1

インポートされたXAPファイルのapp.xamlリソースにアクセスする方法はありますか?Silverlight import App.xamlから動的にxapが読み込まれる

以上、ホストapp.xamlにapp.xaml輸入ゲストは

問題は、インポートされたSilverlightアプリケーションでは、私はすべてのapp.xamlリソースを失った、と私はちょうどホストのリソースを参照してください...私は好きだろうということですそれらをマージする...

可能ですか?

あなたは、リソースファイルのURIを知っていれば、私のような、このよう

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

答えて

0

にXAPをロード: "/ コンポーネント名、コンポーネント/ resourcepathの.xaml" あなたは、

Application.Current.Resources.MergedDictionaries.Add("*resourceuri*");

のようなコードを記述することで、このリソースディクショナリをアプリケーションに簡単に追加できます。 「Application.Current」は、どこで使用されていても、常にランタイムアプリケーションインスタンス(ホストアプリケーション)を指しています。

関連する問題