Example #1
0
        //@@hack: workaround for main view code behind
        /// <summary>
        /// Determines whether this instance can close. This is meant to be called by the view
        /// code behind when testing if a document can close (OnDocumentClosing).
        /// </summary>
        /// <returns>true if can close</returns>
        public bool CanClose()
        {
            if (!IsDirty())
            {
                return(true);
            }

            MessageBoxAction prompt = new MessageBoxAction
            {
                Caption = App.APP_NAME,
                Text    = LocalizedStrings.Format(StringResources.DiscardDocumentChangesPrompt,
                                                  DisplayName),
                Button = MessageBoxButton.YesNo,
                Image  = MessageBoxImage.Question
            };

            bool bResult = true;

            prompt.Completed += (sender, e) =>
            {
                bResult = prompt.Result == MessageBoxResult.Yes;
            };
            prompt.Execute(null);
            return(bResult);
        }
Example #2
0
        /// <summary>
        /// Called to check whether or not this instance can close.
        /// </summary>
        /// <param name="callback">The implementor calls this action with the result
        /// of the close check.</param>
        public override void CanClose(Action <bool> callback)
        {
            // if forcing (@@hack) or not dirty it's OK to close
            if ((_bIsForcedClosing) || (!IsDirty()))
            {
                callback(true);
                return;
            } //eif

            // else prompt user
            MessageBoxAction prompt = new MessageBoxAction
            {
                Caption = App.APP_NAME,
                Text    = LocalizedStrings.Format(StringResources.DiscardDocumentChangesPrompt,
                                                  DisplayName),
                Button = MessageBoxButton.YesNo,
                Image  = MessageBoxImage.Question
            };

            prompt.Completed += (sender, e) =>
            {
                callback(prompt.Result == MessageBoxResult.Yes);
            };
            prompt.Execute(null);
        }