私がしていることは、次のインターフェイスを使用して、シェルにビュー レジストリを作成することです (ここでは簡略化しています)。
public interface IViewRegistry
{
void RegisterView(string title, string key, Func<UIElement> viewCreationMethod);
void OpenView(string key);
}
これは単純化しすぎていますが、うまくいけば、これでイメージが得られます。各モジュールは、初期化時にこのインターフェースを使用して、そのビューをシェルに登録します。私のシェルでは、これらのものを格納する ViewStore を作成します。
public static class ViewStore
{
public Dictionary<string, ViewEntry> Views { get; set; }
static ViewStore()
{
Views = new Dictionary<string, ViewEntry>();
}
public void RegisterView(string name, string key, Func<UIElement> createMethod)
{
Views.Add(key, new ViewEntry() { Name = name, CreateMethod = createMethod });
}
}
次に、私の IViewRegistry 実装から:
public class ViewRegistryService : IViewRegistry
{
public void RegisterView(string title, string key, Func<UIElement> createMethod)
{
ViewStore.RegisterView(title, key, createMethod);
}
public void OpenView(string key)
{
//Check here with your region manager to see if
//the view is already open, if not, inject it
var view = _regionManager.Regions["MyRegion"].GetView(key);
if(view != null)
{
view = ViewStore.Views[key]();
_regionManager.Regions["MyRegion"].Add(view, key);
}
_regionManager.Regions["MyRegion"].Activate(view);
}
private IRegionManager _regionManager;
public ViewRegistryService(IRegionManager rm)
{
_regionManager = rm;
}
}
今、私には2つのことがあります:
- シェルでメニューを作成するために使用できる ViewStore。
- モジュールが、単純な ModuleDependencies を超えて結合することなく、他のモジュールが所有するビューを開く方法 (実際には、ModuleDependency でさえ必要ありませんが、おそらく正しいです。
明らかに、この方法は物事を単純化しすぎています。ビューがメニュー項目であるべきかどうかを示すものがあります。私のアプリにはいくつかのメニューなどがありますが、これは基本的なものであり、うまくいくはずです。
また、Stackoverflow に答えを得るチャンスを少し与えるべきです... あきらめるまでに 3 時間しか与えてくれませんでした :)
お役に立てれば。