Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowConductor"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="view">The view.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="viewModel"/> or <paramref name="view"/> is <see langword="null"/>.
        /// </exception>
        public WindowConductor(object viewModel, Window view)
        {
            if (viewModel == null)
                throw new ArgumentNullException(nameof(viewModel));
            if (view == null)
                throw new ArgumentNullException(nameof(view));

            _viewModel = viewModel;
            _view = view;

            // Set conductor.
            var screen = viewModel as IScreen;
            if (screen != null)
                screen.Conductor = this;

            var activatable = viewModel as IActivatable;
            if (activatable != null)
            {
                activatable.OnActivate();
                activatable.Deactivated += OnDeactivated;
            }

            var guardClose = viewModel as IGuardClose;
            if (guardClose != null)
                view.Closing += OnViewClosing;

            view.Closed += OnViewClosed;
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowConductor"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="view">The view.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="viewModel"/> or <paramref name="view"/> is <see langword="null"/>.
        /// </exception>
        public WindowConductor(object viewModel, Window view)
        {
            if (viewModel == null)
                throw new ArgumentNullException(nameof(viewModel));
            if (view == null)
                throw new ArgumentNullException(nameof(view));

            _viewModel = viewModel;
            _view = view;

            // Set conductor.
            var screen = viewModel as IScreen;
            if (screen != null)
                screen.Conductor = this;

            var activatable = viewModel as IActivatable;
            if (activatable != null)
            {
                activatable.OnActivate();
                activatable.Deactivated += OnDeactivated;
            }

            var guardClose = viewModel as IGuardClose;
            if (guardClose != null)
                view.Closing += OnViewClosing;

            view.Closed += OnViewClosed;
        }