zoukankan      html  css  js  c++  java
  • Prism.Interactivity 和 Prism.Modularity 介绍

    Prism.Interactivity: 主要用来截取View即界面的一些处理,而这些功能通过vm 不好实现,只能用 CommandBehaviorBase 来截取处理,特别是在处理界面异常很有用。

    定义如下:

      public class ValidationExceptionBehavior : Behavior<FrameworkElement>

    // 方法体

    }

    使用:

    界面错误信息的处理:

      <Interactivity:Interaction.Behaviors>                <common:ValidationExceptionBehavior></common:ValidationExceptionBehavior>

                </Interactivity:Interaction.Behaviors>

    键盘事件的处理

     

       <Interactivity:Interaction.Triggers>

                    <Interactivity:EventTrigger EventName="KeyDown">

                        <Interactivity:InvokeCommandAction Command="{Binding ButtonKeyDown}"

                                                   CommandParameter="{Binding RelativeSource={RelativeSource  Mode=FindAncestor, AncestorType={x:Type Window}}}"/>

                    </Interactivity:EventTrigger>

                </Interactivity:Interaction.Triggers>

     

    注意界面要引用:

    xmlns:Interactivity=http://schemas.microsoft.com/expression/2010/interactivity

     

    Prism.Modularity: 模块定义,加载,管理

     

    继承 IModule

     public class PositionModule : IModule

    {

      // 其他内容

     

    ///必须实现 Initialize ,注册该模块中使用的服务,vm 等。提供主程序中使用。

        public void Initialize()

            {    

           .....

                this.container.RegisterType<IOrdersViewModel, OrdersViewModel>();

                this.container.RegisterType<IOrdersView, OrdersView>();

                this.container.RegisterType<IOrderCompositeViewModel, OrderCompositeViewModel>();

                this.container.RegisterType<IPositionSummaryViewModel, PositionSummaryViewModel>();

                this.container.RegisterType<IPositionPieChartViewModel, PositionPieChartViewModel>();

                this.regionManager.RegisterViewWithRegion(RegionNames.MainRegion,

                                                           () => this.container.Resolve<PositionSummaryView>());

                this._ordersController = this.container.Resolve<OrdersController>();

            }

    }

     

    主程序中使用方法:

    在 Bootstrapper 中使用:

    public class StockTraderRIBootstrapper : UnityBootstrapper

        {

            protected override void ConfigureModuleCatalog()

            {

                base.ConfigureModuleCatalog();

     

                ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;                   moduleCatalog.AddModule(typeof(StockTraderRI.Modules.Position.PositionModule));                     moduleCatalog.AddModule(typeof(StockTraderRI.Modules.News.NewsModule));

            }

     

            protected override DependencyObject CreateShell()

            {

                // Use the container to create an instance of the shell.

                Shell view = this.Container.TryResolve<Shell>();

                view.DataContext = new ShellViewModel();

                return view;

            }

     

            protected override void InitializeShell()

            {

                base.InitializeShell();

                App.Current.MainWindow = (Window)this.Shell;

                App.Current.MainWindow.Show();

            }

     

            protected override Prism.Regions.IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()

            {

                var factory = base.ConfigureDefaultRegionBehaviors();

                return factory;

            }

    }

     这是通过代码实现的,也可以通过 xml 配置文件实现

     

    protected override IModuleCatalog CreateModuleCatalog() {     return ModuleCatalog.CreateFromXaml(new Uri("/MyProject;component/ModulesCatalog.xaml", UriKind.Relative)); }

  • 相关阅读:
    SQL Server 2008 如何查看与创建约束
    Hibernate的主键生成策略
    sql server的id字段设置为自动生成的,那么该怎么写insert语句呢?
    org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.bjsxt.model.Student.courses
    INSERT 语句与 FOREIGN KEY 约束"XXX"冲突。该冲突发生于数据库"XXX",表"XXX", column 'XXX。
    在排序数组中查找符合条件的数
    求二叉树中节点的最大距离
    设计包含min 函数的栈
    寻找链表的倒数第K个节点
    翻转句子中单词的顺序
  • 原文地址:https://www.cnblogs.com/tianya/p/13406427.html
Copyright © 2011-2022 走看看