Esempio n. 1
0
        /// <summary>
        /// Gets the modal window that has to be shown to the user.
        /// </summary>
        /// <param name="viewKey"></param>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private Window GetCustomWindow(string viewKey, ModalDialogViewModelBase viewModel)
        {
            if (string.IsNullOrEmpty(viewKey))
            {
                throw new ArgumentException("viewKey");
            }
            if (null == viewModel)
            {
                throw new ArgumentException("viewModel");
            }
            var viewRegistry = ModalViewRegistry.Instance;

            if (!viewRegistry.ContainsKey(viewKey))
            {
                throw new ArgumentException(string.Format("the key is not present in the registry: {0}", viewKey));
            }

            var userControl = viewRegistry.GetViewByKey(viewKey); // Get the UserControl.
            var modalWindow = new ModalCustomMessageDialog
            {
                // Set the content of the window as the user control
                DataContext = viewModel,
                // Set the data context of the window as the ViewModel
                Owner = Util.AppMainWindow,
                // Set the owner of the modal window to the app window.
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                ShowInTaskbar         = false,
                //Set content
                ActualContent = userControl,
                //Adjust height and width
                SizeToContent = SizeToContent.WidthAndHeight,
            };

            modalWindow.Closed += CleanModalWindow;
            return(modalWindow);
        }
Esempio n. 2
0
        /// <summary>
        /// Shows a view identified by the <see cref="viewKey"/> and binds the view to the <see cref="viewModel"/>.
        /// The view is shown as a blocking modal dialog.
        /// </summary>
        /// <param name="viewKey">shows the view identified by the key.</param>
        /// <param name="viewModel">The modal view is bound to this view model.</param>
        void IMessagingService.ShowCustomMessage(string viewKey, ModalDialogViewModelBase viewModel)
        {
            var modalWindow = GetCustomWindow(viewKey, viewModel);

            modalWindow.Show();
        }