Files
wpf-notifyicon/Hardcodet.NotifyIcon.Wpf/Source/Windowless Sample/NotifyIconViewModel.cs
Robin Krom 23186feefe Code modernising (#8)
* Applied some code conventions, used more current language features which should improve readability and making it easier to re-factor / modify. Also fixed some typos in documentation.
* Changes based on PR conversation for the SystemInfo
* Some modifications due to conversations on the PR, especially I removed the FlagsAttribute on the BalloonFlags.
* Removed Silverlight targeting in code.
2019-07-16 14:09:59 +02:00

60 lines
1.8 KiB
C#

using System.Windows;
using System.Windows.Input;
namespace Windowless_Sample
{
/// <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();
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(),
CanExecuteFunc = () => Application.Current.MainWindow != null
};
}
}
/// <summary>
/// Shuts down the application.
/// </summary>
public ICommand ExitApplicationCommand
{
get
{
return new DelegateCommand {CommandAction = () => Application.Current.Shutdown()};
}
}
}
}