如何从功能区窗口捕获 OnClosing 事件?

发布于 2024-10-18 02:36:19 字数 314 浏览 5 评论 0原文

在我的应用程序中,我曾经使用从 System.WIndows.Window 扩展的 wpf 窗口。

我正在考虑将它们迁移到使用从 ToolWindow 扩展的功能区 Windows。

不幸的是,我无法将 OnClosing 事件与功能区窗口一起使用。

如何在窗口关闭时触发?

我需要类似下面的东西

protected override void OnClosing(CancelEventArgs e) {
            e.Cancel = true;
    }

谢谢

In my application I used to use the wpf windows where are extendd from System.WIndows.Window.

I am thinking of migrate them to using Ribbon Windows which are extended From ToolWindow.

Unfortunately I can't use the OnClosing event with Ribbon windows.

How can I trigger when a window is closed?

I need something like the following

protected override void OnClosing(CancelEventArgs e) {
            e.Cancel = true;
    }

Thanks

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

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

发布评论

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

评论(1

淡写薰衣草的香 2024-10-25 02:36:19

试试这个:
在 XAML 添加

<ribbon:RibbonWindow x:Class="RibbonWindowSample.RibbonWindowWord"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
    xmlns:local="clr-namespace:RibbonWindowSample"
    Title="RibbonWindowWord" Height="600" Width="1000"

    Closing="RibbonWindow_Closing"
>
    <TextBlock Text="Hello" />
</ribbon:RibbonWindow>

上关闭代码添加

private void RibbonWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (MessageBox.Show("Confirm?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
        e.Cancel = true;
}

Try this:
on XAML add Closing

<ribbon:RibbonWindow x:Class="RibbonWindowSample.RibbonWindowWord"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
    xmlns:local="clr-namespace:RibbonWindowSample"
    Title="RibbonWindowWord" Height="600" Width="1000"

    Closing="RibbonWindow_Closing"
>
    <TextBlock Text="Hello" />
</ribbon:RibbonWindow>

on Code add

private void RibbonWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (MessageBox.Show("Confirm?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
        e.Cancel = true;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文