Click here to Skip to main content
15,892,674 members
Articles / Desktop Programming / WPF

C.B.R.

Rate me:
Please Sign up or sign in to vote.
4.96/5 (52 votes)
22 Oct 2012GPL329 min read 125.2K   1.8K   132  
Comic and electronic publication reader with library management, extended file conversion, and devices support.
// ****************************************************************************
// <copyright file="DialogMessage.cs" company="GalaSoft Laurent Bugnion">
// Copyright © GalaSoft Laurent Bugnion 2009-2011
// </copyright>
// ****************************************************************************
// <author>Laurent Bugnion</author>
// <email>laurent@galasoft.ch</email>
// <date>12.6.2009</date>
// <project>GalaSoft.MvvmLight.Messaging</project>
// <web>http://www.galasoft.ch</web>
// <license>
// See license.txt in this project or http://www.galasoft.ch/license_MIT.txt
// </license>
// ****************************************************************************

// TODO Win8

#if !WIN8

using System;
using System.Windows;

////using GalaSoft.Utilities.Attributes;

namespace CBR.Core.Helpers
{
    /// <summary>
    /// Use this class to send a message requesting to display a message box with features
    /// corresponding to this message's properties. The Callback property should be used
    /// to notify the message's sender about the user's choice in the message box.
    /// Typically, you can use this message typ's recipient will be an element of the View,
    /// and the sender will possibly be a ViewModel.
    /// </summary>
    ////[ClassInfo(typeof(Messenger))]
    public class DialogMessage : GenericMessage<string>
    {
        /// <summary>
        /// Initializes a new instance of the DialogMessage class.
        /// </summary>
        /// <param name="content">The text displayed by the message box.</param>
        /// <param name="callback">A callback method that should be executed to deliver the result
        /// of the message box to the object that sent the message.</param>
        public DialogMessage(
            string content,
            Action<MessageBoxResult> callback)
            : base(content)
        {
            Callback = callback;
        }

        /// <summary>
        /// Initializes a new instance of the DialogMessage class.
        /// </summary>
        /// <param name="sender">The message's original sender.</param>
        /// <param name="content">The text displayed by the message box.</param>
        /// <param name="callback">A callback method that should be executed to deliver the result
        /// of the message box to the object that sent the message.</param>
        public DialogMessage(
            object sender,
            string content,
            Action<MessageBoxResult> callback)
            : base(sender, content)
        {
            Callback = callback;
        }

        /// <summary>
        /// Initializes a new instance of the DialogMessage class.
        /// </summary>
        /// <param name="sender">The message's original sender.</param>
        /// <param name="target">The message's intended target. This parameter can be used
        /// to give an indication as to whom the message was intended for. Of course
        /// this is only an indication, amd may be null.</param>
        /// <param name="content">The text displayed by the message box.</param>
        /// <param name="callback">A callback method that should be executed to deliver the result
        /// of the message box to the object that sent the message.</param>
        public DialogMessage(
            object sender,
            object target,
            string content,
            Action<MessageBoxResult> callback)
            : base(sender, target, content)
        {
            Callback = callback;
        }

        /// <summary>
        /// Gets or sets the buttons displayed by the message box.
        /// </summary>
        public MessageBoxButton Button
        {
            get;
            set;
        }

        /// <summary>
        /// Gets a callback method that should be executed to deliver the result
        /// of the message box to the object that sent the message.
        /// </summary>
        public Action<MessageBoxResult> Callback
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the caption for the message box.
        /// </summary>
        public string Caption
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets which result is the default in the message box.
        /// </summary>
        public MessageBoxResult DefaultResult
        {
            get;
            set;
        }

#if !SILVERLIGHT
        /// <summary>
        /// Gets or sets the icon for the message box.
        /// </summary>
        public MessageBoxImage Icon
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the options for the message box.
        /// </summary>
        public MessageBoxOptions Options
        {
            get;
            set;
        }
#endif

        /// <summary>
        /// Utility method, checks if the <see cref="Callback" /> property is
        /// null, and if it is not null, executes it.
        /// </summary>
        /// <param name="result">The result that must be passed
        /// to the dialog message caller.</param>
        public void ProcessCallback(MessageBoxResult result)
        {
            if (Callback != null)
            {
                Callback(result);
            }
        }
    }
}

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect
France France
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside

https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/

Comments and Discussions