Silverligthアプリケーションパッケージ(.xapファイル)のサイズが大きい場合、起動されるまで時間が必要となってしまいます。こういう場合、Silverlightアプリケーションを複数の.xapか.zipファイルに分割して、起動時最低限の機能を備えるパッケージを用意し、後から必要なコンテンツリソースをダウンロードすることができます。 動的にリソースをダウンロードするには、WebClientクラスを使用します。WebClientクラスのOpenReadAsyncメソッドによって、ダウンロードしてから、Application.GetResourceStreamメソッドを使用し、リソースのストリーム情報を得られる。 WebClientのOpenReadCompletedのイベント下記のように、分割したリソースを読み込めます。 StreamResourceInfo zipStream = new StreamResourceInfo(e.Result as Stream, null); // 「SubContents.dll」はサブパッケージの名前。 StreamResourceInfo assemblyStream = Application.GetResourceStream(zipStream, new Uri("SubContents.dll", UriKind.Relative)); //ここまで動的にアセンブリをロードするサンプルにも適用する AssemblyPart assemblyPart = new AssemblyPart(); // 現在のアプリケーションドメインにアセンブリをロードします。 Assembly assembly = new AssemblyPart().Load(assemblyStream.Stream); //サブXAPのコンテンツを読み込む Type type = null; if (assembly != null) { type = Type.GetType("SubContents.Views.ExternalAssemblyView" + "," + assembly, false); } if (type != null) { UIElement element = Activator.CreateInstance(type) as UIElement; this.ContentGrid.Children.Add(element); } 超多機能のアクセス解析が永久無料! コメント: |