예제 #1
0
        /// <summary>Displays a message box</summary>
        /// <param name="messageBoxText">Message box text message (plain text)</param>
        /// <param name="caption">Message box caption (title)</param>
        /// <param name="buttons">Standard buttons displayed by the message box</param>
        /// <param name="icon">Standard icon displayed by the message box.</param>
        /// <param name="defaultResult">Default standard button</param>
        /// <param name="onComplete">Code to run when the message box closes.</param>
        /// <param name="actions">Custom actions to be added to the message box as buttons. (Note: If this parameter is not null, the 'buttons' parameter is ignored)</param>
        /// <param name="model">Custom message box view model. (Note: Only used in exceptional scenarios where the standard view model .</param>
        /// <param name="viewName">Name of a custom view to be used by the message box (optional).</param>
        /// <param name="controllerType">Type of the controller (used as a context to find views)</param>
        public static void Message(string messageBoxText = "", string caption = "Message", MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxImages icon = MessageBoxImages.Information, MessageBoxResults defaultResult = MessageBoxResults.OK, Action<MessageBoxResult> onComplete = null, IEnumerable<IViewAction> actions = null, MessageBoxViewModel model = null, string viewName = "", Type controllerType = null)
        {
            var context = new RequestContext(new RouteData("MessageBox", new {viewName = string.Empty, messageBoxText, caption, buttons, icon, defaultResult}));

            // If a controller type was specified, we try to use it, which provides a context to find views
            Controller controller;
            if (controllerType == null) controller = new Controller();
            else controller = Activator.CreateInstance(controllerType) as Controller;
            if (controller == null) controller = new Controller();
            context.ProcessingController = controller;

            if (model != null && onComplete != null) model.OnComplete = onComplete; // Could be used later, especially for test scenarios where queued results simulate closing of message boxes

            bool mustHandle = _messageBoxResultQueue == null || _messageBoxResultQueue.Count == 0;

            context.Result = controller.MessageBox(viewName, messageBoxText, caption, buttons, icon, defaultResult, actions, model);
            var result = context.Result as MessageBoxResult;
            if (result != null && onComplete != null) result.ViewClosed += (o, e) => onComplete(result);

            if (mustHandle)
                // By default, we let view handlers handle the message box, unless simulated results are queued up.
                ExecuteViewHandlers(context);
        }
예제 #2
0
        /// <summary>Displays the specified notification</summary>
        /// <param name="text">Main text</param>
        /// <param name="text2">Secondary text</param>
        /// <param name="number">Numeric information (such as an item count) passed as a string</param>
        /// <param name="imageResource">Generic image resource to load a brush from (if this parameter is passed an the resource is found the image parameter is ignored)</param>
        /// <param name="image">A logo image (passed as a brush).</param>
        /// <param name="model">Notification view model (if passed, text, number, image and overrideTimeout parameters are ignored)</param>
        /// <param name="viewName">Name of a custom view to be used by the status.</param>
        /// <param name="controllerType">Type of the controller (used as a context to find views)</param>
        /// <param name="overrideTimeout">Overrides the theme's default notification timeout. If model is passed, set this property in model.</param>
        public static void Notification(string text = "", string text2 = "", string number = "", string imageResource = "", Brush image = null, NotificationViewModel model = null, string viewName = "", Type controllerType = null, TimeSpan? overrideTimeout = null)
        {
            var context = new RequestContext(new RouteData("NotificationMessage", new {viewName = string.Empty}));

            // If a controller type was specified, we try to use it, which provides a context to find views
            Controller controller;
            if (controllerType == null) controller = new Controller();
            else controller = Activator.CreateInstance(controllerType) as Controller;
            if (controller == null) controller = new Controller();
            context.ProcessingController = controller;

            context.Result = controller.NotificationMessage(viewName, text, text2, number, imageResource, image, model, overrideTimeout);

            ExecuteViewHandlers(context);
        }
예제 #3
0
        /// <summary>Sets the application status (typically displayed in a status bar).</summary>
        /// <param name="message">Message that is to be displayed</param>
        /// <param name="status">Application status</param>
        /// <param name="model">Application status view model</param>
        /// <param name="viewName">Name of a custom view to be used by the status.</param>
        /// <param name="controllerType">Type of the controller (used as a context to find views)</param>
        public static void Status(string message = "", ApplicationStatus status = ApplicationStatus.Ready, StatusViewModel model = null, string viewName = "", Type controllerType = null)
        {
            var context = new RequestContext(new RouteData("StatusMessage", new {viewName = string.Empty}));

            // If a controller type was specified, we try to use it, which provides a context to find views
            Controller controller;
            if (controllerType == null) controller = new Controller();
            else controller = Activator.CreateInstance(controllerType) as Controller;
            if (controller == null) controller = new Controller();
            context.ProcessingController = controller;

            context.Result = controller.StatusMessage(viewName, message, status, model);

            ExecuteViewHandlers(context);
        }
예제 #4
0
        /// <summary>This helper method finds the specified view which can often be useful in special cases, such as associating custom views with actions</summary>
        /// <param name="standardView">Standard view identifier</param>
        /// <param name="controllerType">Type of the controller (used as a context to find views)</param>
        /// <returns>Document as UIElement, or null if not found.</returns>
        public static FrameworkElement LoadView(StandardViews standardView, Type controllerType = null)
        {
            var viewName = "CODEFrameworkStandardView" + standardView;

            // If a controller type was specified, we try to use it, which provides a context to find views
            Controller controller;
            if (controllerType == null) controller = new Controller();
            else controller = Activator.CreateInstance(controllerType) as Controller;
            if (controller == null) controller = new Controller();
            var result = new ViewResult();
            return controller.FindView(viewName, ViewLevel.Normal, result) ? result.View : null;
        }