第527篇-Prism学习系列3_Modularity

在Prism中,一个非常普遍的方法是把各个不同的Business模块化,用Module的机制可以很好的解决这个问题。

Module支持即时加载.

   /// <summary>
    /// A module for the quickstart.
    /// </summary>
    [ModuleExport(typeof(ModuleD))]
    public class ModuleD : IModule
    {
        private readonly IModuleTracker moduleTracker;

        /// <summary>
        /// Initializes a new instance of the <see cref="ModuleD"/> class.
        /// </summary>
        /// <param name="moduleTracker">The module tracker.</param>
        [ImportingConstructor]
        public ModuleD(IModuleTracker moduleTracker)
        {
            if (moduleTracker == null)
            {
                throw new ArgumentNullException("moduleTracker");
            }

            this.moduleTracker = moduleTracker;
            this.moduleTracker.RecordModuleConstructed(WellKnownModuleNames.ModuleD);
        }

        /// <summary>
        /// Notifies the module that it has be initialized.
        /// </summary>
        public void Initialize()
        {
            this.moduleTracker.RecordModuleInitialized(WellKnownModuleNames.ModuleD);
        }
    }

顺便说一下Data Trigger:

 <i:Interaction.Triggers>
                <!-- DataTriggers only work when the dependency property value changes. -->
                <!-- For the quickstart, some modules may initialize before the UI data-binds. -->
                <!-- To accomodate this, the data triggers below bind to a hidden control value that is bound late enough. -->
                <ei:DataTrigger Binding="{Binding ElementName=ModuleStatusTextBlock, Path=Text}" Value="NotStarted">
                    <ei:ChangePropertyAction PropertyName="Background" 
                                             TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                             Value="{StaticResource ModuleControl.NotStarted.BackgroundBrush-Simple}"/>
                    <ei:ChangePropertyAction PropertyName="Foreground" 
                                             TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                             Value="{StaticResource ModuleControl.NotStarted.ForegroundBrush-Simple}"/>
                    <ei:ChangePropertyAction PropertyName="BorderBrush"
                                             TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                             Value="{StaticResource ModuleControl.NotStarted.BorderBrush-Simple}"/>
                    <ei:ChangePropertyAction PropertyName="FontSize" 
                                             TargetObject="{Binding RelativeSource={RelativeSource TemplatedParent}}" 
                                             Value="12"/>
                </ei:DataTrigger>

下载地址:ModularityWithMef

posted @ 2013-03-31 22:06  Shanghai Jim Zhou  阅读(342)  评论(0编辑  收藏  举报