我的WPF應用程序有一個小問題。關閉WPF窗口仍然可見任務欄
我有一個閃屏圖像(作爲XAML窗口)和主要的應用程序(如另一XAML窗口會從飛濺caleld)
即使當我用這個.Close()
上飛濺窗口和工作在主應用程序中, Splash窗口在任務欄中仍然可見。
如果我在主應用程序上使用這個.Close
,我將在任務欄應用程序中有兩個空白窗口,我必須按X完全關閉。
我試過Application.Current.Shutdown()
,但結果相同。
飛濺:
public Splash()
{
InitializeComponent();
}
private void Window_ContentRendered(object sender, EventArgs e)
{
CloseProcedure();
}
public async void CloseProcedure()
{
//Missing data loading which will be async.
UC_Main UCMain = new UC_Main();
MainWindow window = new MainWindow();
window.AppContent.Children.Add(UCMain);
this.Close();
await Task.Delay(500); //for fade effect.
window.Show();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Closing -= Window_Closing;
e.Cancel = true;
var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(0.5));
this.BeginAnimation(UIElement.OpacityProperty, anim);
anim.Completed += (s, _) => this.Close();
}
主要應用
private void BTN_Close_MouseUp(object sender, MouseButtonEventArgs e)
{
this.Close();
}
private void titleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
titleBar.Background = Brushes.White;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Closing -= Window_Closing;
e.Cancel = true;
var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(0.2));
this.BeginAnimation(UIElement.OpacityProperty, anim);
anim.Completed += (s, _) => Application.Current.Shutdown();
}
}
嘗試Environment.Exit(0); – Mainak
檢查此問題http://stackoverflow.com/questions/9992119/wpf-app-doesnt-shut-down-when-closing-main-window –
@Mainak沒有工作。同樣的東西 – DethoRhyne