2

嗨,我为视图导航编写了代码,为此我在该按钮的导航区域上添加了按钮单击我想在内容区域中打开视图我的代码是

模块代码

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);
        }
    }
}

引导是

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>

现在的问题是当我运行我的应用程序按钮时总是显示禁用,任何人都可以告诉我是什么问题以及它的解决方案是什么。

谢谢

4

1 回答 1

0

我得到了这个工作。在关于 Prism 的复数视频视频之后,我使用了相同的代码。

问题是与 CompositeCommand 关联的唯一命令未设置为 Active。将 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.

于 2014-11-20T13:26:56.860 回答