Example #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);
        }
Example #2
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;
        }