我使用烤面包机窗口,这是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;
}
问题是Notifications弹出窗口仍然是任务管理器中的子窗口。每次烤面包机窗口打开(并再次关闭)时,都会添加一个条目。在XAML中,我已经添加了Completed =&#34; DoubleAnimationCompleted&#34;和(在Stackoverflow中的另一篇文章后)故事板已完成=&#34; Storyboard_Completed&#34;&gt;。调用这两种方法并执行此操作。关闭()但弹出窗口不会从任务栏中显示出来。所以this.Close(无论以何种方式调用)似乎都不会清除这些条目。
我可以做些什么来改变它?
答案 0 :(得分:0)
我终于从“CrashproofCode”发布的样本中找到了答案 WPF 'Toaster' Popup - How to close?。在将他的代码与我的代码进行比较之后,我发现了两个差异导致我的代码保留在任务栏中:
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"
仅此一项就足以防止这种情况发生。