Exemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Operation.GlobalThreadException += OnGlobalThreadException;
            Dispatcher.UnhandledException   += OnUnhandledException;

            mApplication = ControllerType != null ? (IOperation)Activator.CreateInstance(ControllerType) : null;
            mViewModel   = ViewModelType != null ? (ViewModel)Activator.CreateInstance(ViewModelType) : null;
            MainWindow   = ViewType != null ? (Window)Activator.CreateInstance(ViewType) : null;

            if (MainWindow != null)
            {
                MainWindow.DataContext = mViewModel;
            }

            var specificApplication = mApplication.CastTo <WpfApplication>();

            if (specificApplication != null)
            {
                specificApplication.Host = this;
                mApplicationController   = specificApplication;

                ServiceLocator.Default.Register <IApplicationHost>(this);
            }

            ViewModel.GlobalPropertyChanged += OnGlobalPropertyChanged;

            var relay = new RelayOperation(() => mApplication?.Run());

            relay.DispatchMode = OperationDispatchMode.BackgroundThread;

            mRunningScope.Enter();
            relay.Run();
            MainWindow?.Show();
        }
Exemplo n.º 2
0
 private void OnGlobalThreadException(object sender, OperationUnhandledExceptionEventArgs e)
 {
     e.Handled = mApplication?.CastTo <WpfApplication>()?.GlobalExceptionHandler(e.Exception) ?? false;
 }