【发布时间】:2013-03-14 10:28:10
【问题描述】:
我有一个包含单个 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 有什么保留,使其不想加载其他内容?
【问题讨论】:
标签: wpf mvvm user-controls mvvm-light contentcontrol