Esempio n. 1
0
 public ViewLoadedHandler(IViewResolver viewProvider, IConventionsHandler conventions, IRegionService regionService, IRegionInjectionHandler autoMappingHandler)
 {
     this.viewProvider       = viewProvider;
     this.conventions        = conventions;
     this.regionService      = regionService;
     this.autoMappingHandler = autoMappingHandler;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FrameworkElementLifecycleNotificationsBehavior"/> class.
        /// </summary>
        /// <param name="broker">The broker.</param>
        /// <param name="conventions">The conventions handler.</param>
        public FrameworkElementLifecycleNotificationsBehavior(IMessageBroker broker, IConventionsHandler conventions)
        {
            this.broker      = broker;
            this.conventions = conventions;

            if (!DesignTimeHelper.GetIsInDesignMode())
            {
                this.loaded = (s, e) =>
                {
                    var view = this.AssociatedObject;
                    var dc   = this.conventions.GetViewDataContext(view, this.conventions.DefaultViewDataContextSearchBehavior);

                    if (this.conventions.ShouldNotifyViewModelLoaded(view, dc))
                    {
                        this.broker.Broadcast(this, new ViewModelLoaded(dc));
                    }

                    if (this.conventions.ShouldNotifyViewLoaded(view))
                    {
                        this.broker.Broadcast(this, new ViewLoaded(view));
                    }

                    var temp = dc as IExpectViewLoadedCallback;
                    if (temp != null)
                    {
                        temp.OnViewLoaded();
                    }
                };
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewResolver"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="conventions">The conventions.</param>
        public ViewResolver(IServiceProvider container, IConventionsHandler conventions)
        {
            Ensure.That(container).Named(() => container).IsNotNull();
            Ensure.That(conventions).Named(() => conventions).IsNotNull();

            this.container   = container;
            this.conventions = conventions;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RegionService"/> class.
        /// </summary>
        /// <param name="regionManagerFactory">The region manager factory.</param>
        /// <param name="conventions">The conventions.</param>
        public RegionService(IRegionManagerFactory regionManagerFactory, IConventionsHandler conventions)
        {
            Ensure.That(regionManagerFactory).Named(() => regionManagerFactory).IsNotNull();
            Ensure.That(conventions).Named(() => conventions).IsNotNull();

            this.regionManagerFactory = regionManagerFactory;
            this.conventions          = conventions;
        }
 public SamplesManager(IConventionsHandler conventions)
 {
     this.Categories = GetAssembly.ThatContains <SamplesManager>()
                       .GetTypes()
                       .Where(t => t.IsAttributeDefined <SampleAttribute>())
                       .GroupBy(t =>
     {
         var sa = t.GetAttribute <SampleAttribute>();
         return(sa.Category);
     })
                       .Select(g =>
     {
         return(new SampleCategory
                (
                    g.Key,
                    g.Select(t => new SampleItem(t, conventions.ResolveViewType(t)))
                    .AsReadOnly()
                ));
     })
                       .AsReadOnly();
 }
Esempio n. 6
0
 public MainViewLoadedHandler(IConventionsHandler conventions, IRegionService regionService, IMessageBroker broker)
 {
     this.conventions   = conventions;
     this.regionService = regionService;
     this.broker        = broker;
 }
 public OpenChildWindowSampleMessageHandler(IViewResolver viewResolver, IConventionsHandler conventions)
 {
     this.viewResolver = viewResolver;
     this.conventions  = conventions;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyObjectCloseHandlerBehavior"/> class.
 /// </summary>
 /// <param name="broker">The broker.</param>
 /// <param name="conventions">The conventions.</param>
 public DependencyObjectCloseHandlerBehavior(IMessageBroker broker, IConventionsHandler conventions)
 {
     this.broker      = broker;
     this.conventions = conventions;
 }
 public AsyncRegionsViewLoadedHandler(IViewResolver viewResolver, IConventionsHandler conventions, IRegionService regionService)
 {
     this.viewResolver  = viewResolver;
     this.conventions   = conventions;
     this.regionService = regionService;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowLifecycleNotificationsBehavior"/> class.
        /// </summary>
        /// <param name="broker">The broker.</param>
        /// <param name="conventions">The conventions handler.</param>
        public WindowLifecycleNotificationsBehavior(IMessageBroker broker, IConventionsHandler conventions)
        {
            Ensure.That(broker).Named(() => broker).IsNotNull();
            Ensure.That(conventions).Named(() => conventions).IsNotNull();

            this.broker      = broker;
            this.conventions = conventions;

            if (!DesignTimeHelper.GetIsInDesignMode())
            {
                logger.Debug("We are not running within a designer.");
                logger.Debug("Ready to attach events.");

                this.loaded = (s, e) =>
                {
                    logger.Debug("Loaded event raised.");
                    Ensure.That(this.AssociatedObject).Named("AssociatedObject").IsNotNull();

                    var view = this.AssociatedObject;
                    var dc   = this.conventions.GetViewDataContext(view, this.conventions.DefaultViewDataContextSearchBehavior);

                    if (this.conventions.ShouldNotifyViewModelLoaded(view, dc))
                    {
                        logger.Debug("ShouldNotifyViewModelLoaded -> true.");

                        this.broker.Broadcast(this, new ViewModelLoaded(dc));

                        logger.Debug("Message broadcasted.");
                    }

                    if (this.conventions.ShouldNotifyViewLoaded(view))
                    {
                        logger.Debug("ShouldNotifyViewLoaded -> true.");

                        this.broker.Broadcast(this, new ViewLoaded(view));

                        logger.Debug("Message broadcasted.");
                    }

                    var temp = dc as IExpectViewLoadedCallback;
                    if (temp != null)
                    {
                        logger.Debug("DataContext is IExpectViewLoadedCallback.");

                        temp.OnViewLoaded();

                        logger.Debug("DataContext.OnViewLoaded() invoked.");
                    }
                };

                logger.Debug("Loaded event attached.");

                this.activated = (s, e) =>
                {
                    var view = this.AssociatedObject;
                    var dc   = this.conventions.GetViewDataContext(view, this.conventions.DefaultViewDataContextSearchBehavior);

                    if (dc != null && dc.GetType().IsAttributeDefined <NotifyActivatedAttribute>())
                    {
                        this.broker.Broadcast(this, new ViewModelActivated(dc));
                    }

                    var temp = dc as IExpectViewActivatedCallback;
                    if (temp != null)
                    {
                        logger.Debug("DataContext is IExpectViewActivatedCallback.");

                        temp.OnViewActivated();

                        logger.Debug("DataContext.OnViewActivated() invoked.");
                    }
                };

                logger.Debug("Activated event attached.");

                this.rendered = (s, e) =>
                {
                    logger.Debug("Rendered event raised.");

                    var view = this.AssociatedObject;
                    var dc   = this.conventions.GetViewDataContext(view, this.conventions.DefaultViewDataContextSearchBehavior);

                    if (dc != null && dc.GetType().IsAttributeDefined <NotifyShownAttribute>())
                    {
                        this.broker.Broadcast(this, new ViewModelShown(dc));
                    }

                    var temp = dc as IExpectViewShownCallback;
                    if (temp != null)
                    {
                        logger.Debug("DataContext is IExpectViewShownCallback.");

                        temp.OnViewShown();

                        logger.Debug("DataContext.OnViewShown() invoked.");
                    }
                };


                logger.Debug("Rendered event attached.");

                this.closed = (s, e) =>
                {
                    logger.Debug("Closed event raised.");

                    var view = this.AssociatedObject;
                    var dc   = this.conventions.GetViewDataContext(view, this.conventions.DefaultViewDataContextSearchBehavior);

                    if (dc != null && dc.GetType().IsAttributeDefined <NotifyClosedAttribute>())
                    {
                        this.broker.Broadcast(this, new ViewModelClosed(dc));
                    }

                    var temp = dc as IExpectViewClosedCallback;
                    if (temp != null)
                    {
                        logger.Debug("DataContext is IExpectViewClosedCallback.");

                        temp.OnViewClosed();

                        logger.Debug("DataContext.OnViewClosed() invoked.");
                    }

                    this.conventions.ViewReleaseHandler(view, ViewReleaseBehavior.Default);
                };


                logger.Debug("Closed event attached.");

                this.closing = (s, e) =>
                {
                    logger.Debug("Closing event raised.");

                    var view = this.AssociatedObject;
                    var dc   = this.conventions.GetViewDataContext(view, this.conventions.DefaultViewDataContextSearchBehavior);

                    var temp = dc as IExpectViewClosingCallback;
                    if (temp != null)
                    {
                        logger.Debug("DataContext is IExpectViewClosingCallback.");

                        temp.OnViewClosing(e);

                        logger.Debug("DataContext.OnViewClosing() invoked.");
                    }
                };


                logger.Debug("Closing event attached.");
            }
            else
            {
                logger.Information("We are running within a designer.");
            }
        }