Beispiel #1
0
        /// <summary>
        ///     Creates an instance of <see cref="InteractionContext" /> from <see cref="InteractionRequestEventArgs" />
        ///     —оздет контекст <see cref="InteractionContext" /> дл¤ запроса <see cref="InteractionRequestEventArgs" />
        /// </summary>
        /// <param name="args">An instance of <see cref="InteractionRequestEventArgs" /> to convert from</param>
        /// <returns>Created instance of <see cref="InteractionContext" /></returns>
        public static InteractionContext FromArguemnts(InteractionRequestEventArgs args)
        {
            IInteractionView      view      = args.InteractionProvider.InteractionView;
            IInteractionViewModel viewModel = args.InteractionProvider.InteractionViewModel;

            view.DataContext = viewModel;

            return(new InteractionContext
            {
                Invoker = args.InterceptorsInvoker,
                Callback = args.Callback,
                ViewModel = viewModel,
                View = view
            });
        }
        /// <summary>
        ///     Вызывается при выводе интерактивных окон
        /// </summary>
        /// <param name="args"></param>
        private void OnModalDialogInteraction(InteractionRequestEventArgs args)
        {
            if (args.IsCanceled)
            {
                if (this._context == null)
                {
                    return;
                }
                DestroyDialog();
                return;
            }

            /*TODO: deal with multiple dialogs request.*/
            if (this._context != null)
            {
                return;
            }
            this._context = InteractionContext.FromArguemnts(args);

            EventHandler closeHandler = null;

            closeHandler = (sender, ar) =>
            {
                this._context.ViewModel.OnInteractionComplete -= closeHandler;
                this._context.Callback();
            };
            this._context.BeforeInitialization();

            this._context.ViewModel.OnInteractionComplete += closeHandler;
            this._context.CurrentViewContent = new InteractionViewContent {
                Content = this._context.View
            };
            this._context.CurrentViewContent.SetValue(Grid.RowSpanProperty,
                                                      AssociatedObject.RowDefinitions.Count == 0 ? 1 : AssociatedObject.RowDefinitions.Count);
            this._context.CurrentViewContent.SetValue(Grid.ColumnSpanProperty,
                                                      AssociatedObject.ColumnDefinitions.Count == 0 ? 1 : AssociatedObject.ColumnDefinitions.Count);
            AssociatedObject.Children.Add(this._context.CurrentViewContent);

            this._context.AfterInitialization();
        }