简体   繁体   English

在任务管理器中无法关闭烤面包机窗口

[英]Toaster Window does not close in Task Manager

I use a toaster window , this is the main part of the XAML: 我使用烤面包机窗口,这是XAML的主要部分:

    <Grid.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard>
                <Storyboard Completed="Storyboard_Completed">
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" Duration="0:0:10" Completed="DoubleAnimationCompleted">
                        <SplineDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
                        <SplineDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
                        <SplineDoubleKeyFrame KeyTime="0:0:12" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>

Basically it's called with a Show method like this: 基本上是使用Show方法调用的,如下所示:

    public new void Show()
    {
        this.Topmost = true;
        base.Show();

        this.Owner = System.Windows.Application.Current.MainWindow;
        this.Closed += this.NotificationWindowClosed;
        var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;

        this.Left = workingArea.Right - this.ActualWidth;
        double top = workingArea.Bottom - this.ActualHeight;
        foreach (Window window in System.Windows.Application.Current.Windows)
        {
            string windowName = window.GetType().Name;

            if (windowName.Equals("NotificationWindow") && window != this)
            {
                window.Topmost = true;
                top = window.Top - window.ActualHeight;
            }
        }

        this.Top = top;
    }

The problem is that the Notifications popup remain as a subwindow in the Task Manager. 问题在于,“通知”弹出窗口保留为“任务管理器”中的子窗口。 Every time a toaster windows opens (and closes again) an entry is added. 每次烤面包机窗口打开(并再次关闭)时,都会添加一个条目。 In the XAML I already added Completed="DoubleAnimationCompleted" and (following another post in Stackoverflow) a Storyboard Completed="Storyboard_Completed">. 在XAML中,我已经添加了Completed =“ DoubleAnimationCompleted”和一个Storyboard Completed =“ Storyboard_Completed”>(在Stackoverflow中的另一篇文章之后)。 Both methods are called and exectute this.Close() but the popups do not diasappear from the taskbar. 这两个方法都被调用并执行this.Close(),但是弹出窗口不会从任务栏上消失。 So this.Close (in whatever way called) seems not to clear these entries. 因此,this.Close(以任何方式调用)似乎无法清除这些条目。

What can I do to change that? 我该怎么做才能改变这种状况?

I finally found the answer from a sample posted by "CrashproofCode" in this WPF 'Toaster' Popup - How to close? 我终于在WPF“烤面包机”弹出窗口-如何关闭中从“ CrashproofCode”发布的示例中找到了答案 . After comparing his code to mine I found 2 differences which caused my code to remain in the taskbar: 在将他的代码与我的代码进行比较之后,我发现2个差异导致我的代码保留在任务栏中:

WindowStyle="None" AllowsTransparency="True" Background="Transparent" Closing="Window_Closing"

The Window_Closing was called and apparently caused the problem: Window_Closing被调用,显然引起了问题:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (!closeCompleted)
    {
        e.Cancel = true;
    }
}

He also had in his XAML: 他在XAML中也有:

ShowInTaskbar="False"

and that alone is sufficient to prevent that too. 仅此一项就足以防止这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM