您好我为视图导航编写了代码,为此我在该按钮上的导航区域添加了按钮单击我要在内容区域中打开视图我的代码是
ModuleCode
public class ClientModule : ModuleBase
{
public ClientModule(IUnityContainer container, IRegionManager regionManager)
: base(container, regionManager) { }
protected override void InitializeModule()
{
RegionManager.RegisterViewWithRegion("NavigationRegion", typeof(Navigation));
RegionManager.RegisterViewWithRegion("ContentRegion", typeof(Content));
}
protected override void RegisterTypes()
{
Container.RegisterType<object, Navigation>(typeof(Navigation).FullName);
Container.RegisterType<object,Content>(typeof(Content).FullName);
}
}
}
Bootstrap
public class Bootstrapper : UnityBootstrapper
{
protected override DependencyObject CreateShell()
{
return this.Container.Resolve<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)this.Shell;
App.Current.MainWindow.Show();
}
protected override void ConfigureContainer()
{
base.ConfigureContainer();
Container.RegisterType<IShellViewModel, ShellViewModel>();
}
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
mappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>());
return mappings;
}
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
moduleCatalog.AddModule(typeof(ClientModule));
}
}
我的导航视图有1个按钮,如下所示
<StackPanel>
<Button Command="{x:Static infCommands:ApplicationCommands.NavigateCommand}"
CommandParameter="{x:Type views:Content}"
Name="btnTest">Navigate to Content</Button>
</StackPanel>
现在问题是当我运行我的应用程序按钮时总是显示禁用,任何人都可以告诉我这是什么问题以及它的解决方案是什么。
由于
答案 0 :(得分:0)
我得到了这个工作。 我在使用关于Prism的复数视频后使用相同的代码。
问题是与CompositeCommand相关联的唯一命令未设置为“活动”。将IsActive设置为true后,CompositeCommand变为活动状态,并启用了按钮。
以下是来自Prism的msdn文档
The CompositeCommand can be configured to evaluate the active status of child DelegateCommands (in addition to the CanExecute status) by specifying true for the monitorCommandActivity parameter in the constructor. When this parameter is set to true, the CompositeCommand class will consider each child DelegateCommand's active status when determining the return value for the CanExecute method and when executing child commands within the Execute method.
When the monitorCommandActivity parameter is true, the CompositeCommand class exhibits the following behavior:
CanExecute. Returns true only when all active commands can be executed. Child commands that are inactive will not be considered at all.
Execute. Executes all active commands. Child commands that are inactive will not be considered at all.