/// <summary> /// Attaches the model and the view. /// </summary> /// <param name="model">The model.</param> /// <param name="view">The view.</param> /// <param name="context">The context.</param> protected virtual void AttachTo(object model, object view, object context) { Action.SetTarget(view as DependencyObject, model); var metadataContainer = model as IMetadataContainer; if (metadataContainer != null) { metadataContainer.SetView(view, context, true); } var viewAware = model as IViewAware; if (viewAware != null) { var element = view as FrameworkElement; if (element != null) { element.Loaded += delegate { viewAware.ViewLoaded(element, context); }; element.Unloaded += delegate { viewAware.ViewUnloaded(element, context); }; } #if !SILVERLIGHT else { var contentElement = view as FrameworkContentElement; if (contentElement != null) { contentElement.Loaded += delegate { viewAware.ViewLoaded(contentElement, context); }; contentElement.Unloaded += delegate { viewAware.ViewUnloaded(element, context); }; } } #endif } }
/// <summary> /// Initializes the core. /// </summary> /// <param name="serviceLocator">The service locator.</param> public override void Initialize(IServiceLocator serviceLocator) { Execute.Initialize(serviceLocator.GetInstance <IDispatcher>()); base.Initialize(serviceLocator); var controller = serviceLocator.GetInstance <IRoutedMessageController>(); var messageBinder = serviceLocator.GetInstance <IMessageBinder>(); var parser = serviceLocator.GetInstance <IParser>(); var conventionManager = serviceLocator.GetInstance <IConventionManager>(); var viewModelBinder = serviceLocator.GetInstance <IViewModelBinder>(); var viewModelDescriptionFactory = serviceLocator.GetInstance <IViewModelDescriptionFactory>(); parser.RegisterMessageParser("Action", new ActionMessageParser(conventionManager, messageBinder)); parser.RegisterMessageParser("ResourceCommand", new CommandMessageParser(conventionManager, messageBinder, CommandSource.Resource)); parser.RegisterMessageParser("ContainerCommand", new CommandMessageParser(conventionManager, messageBinder, CommandSource.Container)); parser.RegisterMessageParser("BoundCommand", new CommandMessageParser(conventionManager, messageBinder, CommandSource.Bound)); Message.Initialize( controller, parser ); Action.Initialize( controller, viewModelDescriptionFactory, serviceLocator ); View.Initialize( serviceLocator.GetInstance <IViewLocator>(), viewModelBinder ); ScreenExtensions.Initialize( serviceLocator.GetInstance <IViewModelFactory>() ); ViewConventionBase.Initialize( messageBinder, viewModelDescriptionFactory, serviceLocator.GetInstance <IValidator>() ); Bind.Initialize(viewModelBinder); Coroutine.Initialize( serviceLocator, serviceLocator.GetInstance <IBuilder>(), parentEnumeratorFactory ); if (!registerItemsWithSubjects) { return; } var registry = serviceLocator.GetInstance <IRegistry>(); var assemblySource = serviceLocator.GetInstance <IAssemblySource>(); assemblySource.Apply(x => RegisterItemsWithSubjects(registry, x)); assemblySource.AssemblyAdded += assembly => RegisterItemsWithSubjects(registry, assembly); }