Hi,
I download this project Prism Splash Screen Module from CodePlex and I have it working for myMEF application, but I found that only the TextBlock control works. I can't get aListView, TextBox, ListBox, etc,. to work on the start-up splash screen.
Getting this un-explain error when I Invoke the splash screen view:
You can down load the code and try the same thing to better understand, but here is the code part:
namespace Natsar.Module.SplashScreen { using System.ComponentModel.Composition; using Microsoft.Practices.Prism.Logging; using Microsoft.Practices.Prism.MefExtensions.Modularity; using Microsoft.Practices.Prism.Modularity; using Microsoft.Practices.Prism.Events; using Microsoft.Practices.ServiceLocation; using Natsar.Infrastructure.Interfaces; using Events; using Views; [ModuleExport(typeof(SplashScreenModule), InitializationMode = InitializationMode.OnDemand, DependsOnModuleNames = new string[] { "InfrastructureModule" })] public class SplashScreenModule : IModule { private IEventAggregator EventAggregator { get; set; } private IShell Shell { get; set; } private AutoResetEvent WaitForCreation { get; set; } [ImportingConstructor] public SplashScreenModule(IEventAggregator eventAggregator, IShell shell) { try { ///ArgumentNullException : need to add excpetion handling if (eventAggregator == null) { throw new ArgumentNullException("eventAggregator"); } if (shell == null) { throw new ArgumentNullException("shell"); } this.EventAggregator = eventAggregator; this.Shell = shell; } catch (Exception msg) { StringBuilder sMsg = new StringBuilder(); sMsg.Append("Message: ").Append(msg.Message).AppendLine(); sMsg.Append("InnerException: ").Append(msg.InnerException).AppendLine(); sMsg.Append("Source: ").Append(msg.Source).AppendLine(); sMsg.Append("StackTrace: ").Append(msg.StackTrace).AppendLine(); ///TODO: Put in logic to send exception #if (DEBUG) Console.WriteLine(sMsg.ToString()); MessageBox.Show(sMsg.ToString(), this.GetType().ToString()); #endif } } /// <summary> /// Notifies the module that it has be initialized. /// </summary> public void Initialize() { Debug.WriteLine("SplashScreenModule instantiation"); Dispatcher.CurrentDispatcher.BeginInvoke( (Action)(() => { Shell.Show(); EventAggregator.GetEvent<CloseSplashEvent>().Publish(new CloseSplashEvent()); })); WaitForCreation = new AutoResetEvent(false); ThreadStart showSplash = () => { Dispatcher.CurrentDispatcher.BeginInvoke( (Action)(() => { SplashScreenView splash = ServiceLocator.Current.GetInstance<SplashScreenView>(); EventAggregator.GetEvent<CloseSplashEvent>().Subscribe( e => splash.Dispatcher.BeginInvoke((Action)splash.Close), ThreadOption.PublisherThread, true); splash.Show(); WaitForCreation.Set(); })); Dispatcher.Run(); }; var thread = new Thread(showSplash) { Name = "Splash Thread", IsBackground = true }; thread.SetApartmentState(ApartmentState.STA); thread.Start(); WaitForCreation.WaitOne(); } } }
I call this from my Bootstrapper.cs:
public class NatsarBootstrapper : MefBootstrapper { #region Private Properties private IEventAggregator EventAggregator { get { return ServiceLocator.Current.GetInstance<IEventAggregator>(); } } #endregion protected override void InitializeModules() { IModuleManager manager = ServiceLocator.Current.GetInstance<IModuleManager>(); manager.LoadModule("SplashScreenModule"); EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent { Message = "DocumentsModule" }); manager.LoadModule("DocumentsModule"); } ... .. . }
Is there anything I can do different to make this work? What I'm doing is showing initialization messages as I load modules and data during start-up. I want to show each message in a list instead of on a singleTextBlock, just to keep the user amusement.
I can live with the single TextBlock message, but would prefer using a ListBox.
Code is like a box of chocolates!...