Пример #1
0
        private void Initialize()
        {
            _window.Closed += HandleWindowClosedToDisconnected;

            _screenOps = new ScreenLifecycleOperations(_aggregator, _screen);
            _screenOps.Activate();

            try {
                bool windowImplementsViewInterface = ViewFactory.TryInitializeView(_window, _screen);
                if (!windowImplementsViewInterface)
                {
                    _window.Content = ViewFactory.CreateView(_screen);
                }
            } catch (Exception ex) {
                if (!ex.IsCritical())
                {
                    CloseScreen(checkState: false);
                }

                throw;
            }

            _screen.Children.Add(this);

            _aggregator.Publish(
                WindowService.InitializeWindowEvent,
                new InitializeWindowEventArgs(_screen, _window)
                );

            AttachHandlers();
        }
Пример #2
0
        public static void HandleModelChanged(DependencyObject view, DependencyPropertyChangedEventArgs e)
        {
            Check.NotNull(view, nameof(view));

            object model = e.NewValue;

            //if (ViewFactory.TryInitializeView(view, model)) {
            //   return;
            //}

            ContentControl contentControl = view as ContentControl;

            if (contentControl != null)
            {
                if (!ViewFactory.TryInitializeView(contentControl.Content, model))
                {
                    contentControl.Content = ViewFactory.CreateView(model);
                }
                return;
            }

            ContentPresenter presenter = view as ContentPresenter;

            if (presenter != null)
            {
                if (!ViewFactory.TryInitializeView(presenter.Content, model))
                {
                    presenter.Content = ViewFactory.CreateView(model);
                }
                return;
            }

            // TODO: Update exception text...
            throw new ArgumentException(
                      ExceptionTexts.UnsupportedTargetTypeForModelProperty.FormatWith(
                          view.GetType().Name,
                          e.NewValue != null ? model.GetType().Name : "ANYTYPE"
                          )
                      );
        }