Witam,
znalazłem przykłady w internecie do umieszczania aplikacji w pasku notification area(przy zegarku)(http://www.hardcodet.net/wpf-notifyicon).
Postanowiłem napisać sobie aplikację wyłączająca system po upływie wybranego czasu(taki stoper). Przed schowaniem aplikacji do paska w kontrolce label, co sekundę odliczam ile czasu pozostało do zamknięcia. Po zmnimalizowaniu appki do paska i ponownym jej przywróceniu, stopera brak-okno tworzy się na nowo. Czy ktoś może mi napisać jak zrobić żeby licznik po przywróceniu aplikacji wskazywał aktualną wartość? Poniżej kod( z internetu) do minimalizowania do paska:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace Czasowy_Wylacznik_PC
{
/// <summary>
/// Provides bindable properties and commands for the NotifyIcon. In this sample, the
/// view model is assigned to the NotifyIcon in XAML. Alternatively, the startup routing
/// in App.xaml.cs could have created this view model, and assigned it to the NotifyIcon.
/// </summary>
public class NotifyIconViewModel
{
/// <summary>
/// Shows a window, if none is already open.
/// </summary>
public ICommand ShowWindowCommand
{
get
{
return new DelegateCommand
{
CanExecuteFunc = () =>Application.Current.MainWindow == null,
CommandAction = () =>
{
Application.Current.MainWindow = new MainWindow();//chyba tutaj jest problem..
// Application.Current.MainWindow.me
//Application.Current.MainWindow.Show();
}
};
}
}
/// <summary>
/// Hides the main window. This command is only enabled if a window is open.
/// </summary>
public ICommand HideWindowCommand
{
get
{
return new DelegateCommand
{
// CommandAction = () => Application.Current.MainWindow.Close(),
CommandAction = () => Application.Current.MainWindow.Hide(), //zmieniłem na hide, bylo jak wyzej Close()
CanExecuteFunc = () => Application.Current.MainWindow != null,
};
}
}
/// <summary>
/// Shuts down the application.
/// </summary>
public ICommand ExitApplicationCommand
{
get
{
return new DelegateCommand { CommandAction = () => Application.Current.Shutdown() };
}
}
}
/// <summary>
/// Simplistic delegate command for the demo.
/// </summary>
public class DelegateCommand : ICommand
{
public Action CommandAction { get; set; }
public Func<bool> CanExecuteFunc { get; set; }
public void Execute(object parameter)
{
CommandAction();
}
public bool CanExecute(object parameter)
{
return CanExecuteFunc == null || CanExecuteFunc();
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
}