単一のContentControlを保持するMainViewがありますが、ContentControlは、アプリケーションのロード時にデフォルトのユーザーコントロールをロードします。
<ContentControl x:Name="MainContentArea" Content="{Binding ActiveControl}"/>
ロードされたユーザーコントロールは、いくつかのプラグイン(無関係)をロードし、コンボボックスからアイテムを選択すると、MVVM LightのViewModelLocatorの概念を使用してParent(MainViewModel)に存在するICommandをトリガーします。
private void CreateSelectedPlugin(IExtendedUIViewFactory plugin)
{
var pluginStartControl = plugin.Create();
_locator.Main.DefaultCommand.Execute(pluginStartControl);
}
問題は、ContentControlが更新されていないことです。ブレークポイントを設定して、コマンドがMainViewModelで実行され、送信した変数が有効であることを確認できます。
public ICommand DefaultCommand { get; set; }
public MainWindowViewModel()
{
DefaultCommand = new RelayCommand<object>(LoadSection, o => true);
}
private void LoadSection(object plugin)
{
ActiveControl = plugin;
//does not matter if i set it to null here
}
MainView / MainViewModelから、ContentControlをnullに設定するだけのLoadSectionまたはtestfunctionを呼び出すと、期待どおりに機能します。
コントロール内から送信するコマンドは、他のものをロードしたくないようにするContentcontrolにどのようなホールドを持っていますか?