Avalon Dock 文档内容在关闭前保存 C#

发布于 2024-11-16 10:43:59 字数 144 浏览 5 评论 0原文

我在一个类似于 notepad++ 的项目中使用 Avalon Dock,我将文档作为文档内容,我面临的问题是,当用户关闭文档内容时,

如果他/她想要保存,我希望他收到弹出消息关闭前的文档。

我怎样才能做到这一点?

先感谢您。

I am using Avalon Dock in a project that's similar 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早乙女 2024-11-23 10:43:59

在我使用的 AvalonDock 版本 (1.2.2668.0) 中,我可以简单地为 DocumentContent 的 Closing 事件定义一个处理程序。

向 DocumentContent 添加处理程序的示例,我向 Closing 事件添加处理程序:

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

示例处理程序:

    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;
        }

希望这会有所帮助,如果没有,您使用的是哪个版本的 AvalonDock?
}

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?
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文