generic.xamlファイルを持つSilverlightアプリケーションがあります。 一般的なファイルでは、他のDLLからMEFによってインポートされた辞書をマージしたいと思います。Silverlight MEF - リソースをインポートしてgeneric.xmalに入れる
どうすればいいですか? (一例がいいでしょう)
generic.xamlファイルを持つSilverlightアプリケーションがあります。 一般的なファイルでは、他のDLLからMEFによってインポートされた辞書をマージしたいと思います。Silverlight MEF - リソースをインポートしてgeneric.xmalに入れる
どうすればいいですか? (一例がいいでしょう)
特定のモジュールが1つロードされたときにこれを行い、うまくいきます。モジュールのコンストラクタで
、リソースをロードするメソッドの呼び出しを追加する - これがうまく機能し、このようにそれをすることによって、私は不足しているリソースの例外で通知されるので:
addResourceDictionaries();
protected void addResourceDictionaries()
{
LoadResource (new Uri("/NAME_OF_DLL;component/assets/name_and_path_of_xaml.xaml", UriKind.Relative));
}
private void LoadResource(Uri uri)
{
var info = System.Windows.Application.GetResourceStream(uri);
string xaml;
using (var reader = new System.IO.StreamReader(info.Stream))
{
xaml = reader.ReadToEnd();
}
ResourceDictionary result = System.Windows.Markup.XamlReader.Load(xaml) as ResourceDictionary;
if (result != null)
{
System.Windows.Application.Current.Resources.MergedDictionaries.Add(result);
}
}
輸出MEFとの私のResourceDictionary
[ExportResourceDictionary]
public partial class MyResourcen : ResourceDictionary
{
public MyResourcen()
{
InitializeComponent();
}
}
ヨーヨーに新しいクラスファイルを追加します(単にあなたのResourceDictionaryには.csファイルを追加します):私は、次の使用しますウルXAML
<ResourceDictionary x:Class="Test.Resourcen.MyResourcen">
が、少なくともここ
[ImportMany("Resourcen", typeof(ResourceDictionary), AllowRecomposition = true)]
private IEnumerable<ResourceDictionary> ImportResourcen { get; set; }
#region Implementation of IPartImportsSatisfiedNotification
public void OnImportsSatisfied()
{
foreach (var dic in ImportResourcen)
{
this.Resources.MergedDictionaries.Add(dic);
}
}
#endregion
例えばapp.xaml、あなたが欲しいのリソースをインポートするには、私はSilverlightのタグを見落とすexportattribute
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class ExportResourceDictionaryAttribute : ExportAttribute
{
public ExportResourceDictionaryAttribute() : base("Resourcen", typeof(ResourceDictionary))
{
}
}
あり、それが動作するかどうか知りませんそこ – blindmeis