2016-11-22 81 views
0

我用一个烤面包机窗口,这是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> 

基本上这就是所谓的用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; 
    } 

问题在于“通知”弹出窗口保留为任务管理器中的子窗口。每次烤面包机窗口打开(并再次关闭)时,都会添加一个条目。在XAML中,我已经添加了Completed =“DoubleAnimationCompleted”和(在Stackoverflow中的另一篇文章之后)Storyboard Completed =“Storyboard_Completed”>。这两种方法都被调用并执行this.Close(),但弹出窗口不会从任务栏中消失。所以this.Close(以任何方式调用)似乎不清除这些条目。

我该怎么做才能改变这种状况?

回答

0

我终于找到了这个 WPF 'Toaster' Popup - How to close?中的“CrashproofCode”发布的样本的答案。他的代码比较矿难发生后,我发现2个差异造成我的代码留在任务栏:

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

的WINDOW_CLOSING被称为显然引起了问题:

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

他也有他的XAML :

ShowInTaskbar="False" 

并且单独就足以防止这种情况发生。