开发者

Avalon Dock Document Content Save Before Closing C#

开发者 https://www.devze.com 2023-03-14 13:11 出处:网络
I am using Avalon Dock in a project that\'s sim开发者_运维问答ilar to notepad++i have the documents as Document content, the problem that im facing is that when a user closes a document content

I am using Avalon Dock in a project that's sim开发者_运维问答ilar to notepad++ i have the documents as Document content, the problem that im facing is that when a user closes a document content

i want him to get a pop up msg if he/she wants to save the document before closing.

How can i accomplish this?

Thank you in advance.


In the version of AvalonDock I'm using (1.2.2668.0), I can simply define a handler for the Closing event of a DocumentContent.

example for adding a handler to a DocumentContent, I am adding a handler to the Closing event:

DocumentContent dc = new DocumentContent();
dc.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(dc_Closing);

The sample handler:

    void dc_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        MessageBoxResult Res = MessageBox.Show("Do you want to save?", "Save document?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
        switch (Res)
        {
            case MessageBoxResult.Cancel:
                //User cancelled, he probably doesn't want to close the window
                e.Cancel = true; 
                break;
            case MessageBoxResult.No:
                //Nothing to do - continue closing
                e.Cancel = false;
                break;
            case MessageBoxResult.Yes:
                //He does want to save - launch save here!
                Save_Function_For_DocumentContent(sender);
                e.Cancel = false;
                break;
            default:
                //Something unexpected, better abort
                e.Cancel = true; 
                break;
        }

Hope this helps, if not, which version of AvalonDock are you using? }

0

精彩评论

暂无评论...
验证码 换一张
取 消