我有一個應用程序,通過點擊「關閉」按鈕,使系統托盤最小化,我想保存它的狀態(位置,所有元素(組合框,文本框)與他們的值等) 。保存窗口狀態,當應用程序在托盤
現在,我寫了這個代碼,但它創建了一個新的窗口,從托盤(而不是恢復舊的,其參數):
# app.xaml.cs:
this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
// create a system tray icon
var ni = new System.Windows.Forms.NotifyIcon();
ni.Visible = true;
ni.Icon = QuickTranslator.Properties.Resources.MainIcon;
ni.DoubleClick +=
delegate(object sender, EventArgs args)
{
var wnd = new MainWindow();
wnd.Visibility = Visibility.Visible;
};
// set the context menu
ni.ContextMenu = new System.Windows.Forms.ContextMenu(new[]
{
new System.Windows.Forms.MenuItem("About", delegate
{
var uri = new Uri("AboutWindow.xaml", UriKind.Relative);
var wnd = Application.LoadComponent(uri) as Window;
wnd.Visibility = Visibility.Visible;
}),
new System.Windows.Forms.MenuItem("Exit", delegate
{
ni.Visible = false;
this.Shutdown();
})
});
我怎麼能修改此代碼爲我的問題嗎?
不要關閉並重新創建窗口,只需隱藏它。 – 2013-04-30 13:51:12
好吧,我做了,但我怎麼能從'App.xaml.cs'獲得MainWindow實例的恢復窗口? – 2013-04-30 13:54:35