Esempio n. 1
0
        /// <summary>
        /// Shows a dialog asynchronously
        /// </summary>
        /// <param name="sender">The object that is launching the dialog</param>
        /// <param name="dialog">The dialog to be shown</param>
        /// <returns>The task that is used to open the dialog or null if no listener is found</returns>
        public static Task ShowDialogAsync(object sender, BaseDialog dialog)
        {
            var type = sender.GetType();

            DialogContainer genericListener  = null,
                            specificListener = null;

            foreach (var listener in _Listeners)
            {
                if (listener.Item2.Equals(type))
                {
                    // We found a listener specific for that type, so let's use that
                    specificListener = listener.Item1;
                    break;
                }
                else if (listener.Item2.IsAssignableFrom(type))
                {
                    /* In case we don't find a specific listener, use any that subscribed
                     * for a type that is a parent class of the sender
                     *
                     * For example, if the sender is a Window and we find no one listening
                     * for that specific type, we could use someone who's listening for an
                     * UIElement. */
                    genericListener = listener.Item1;
                }
            }

            if (specificListener != null)
            {
                specificListener.DisplayDialogAsync(dialog);

                return(dialog.WaitForLoadAsync());
            }
            else if (genericListener != null)
            {
                genericListener.DisplayDialogAsync(dialog);

                return(dialog.WaitForLoadAsync());
            }

            _DialogsOnQueue.Add(new Tuple <Type, BaseDialog>(type, dialog));

            return(null);
        }