1 Star 0 Fork 1

WalterWhite/KnifeZ.Byeol

forked from KnifeZ/KnifeZ.Byeol 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
NotifyIconViewModel.cs 2.67 KB
一键复制 编辑 原始数据 按行查看 历史
KnifeZ 提交于 2020-06-30 10:42 . 修改最小化到任务栏方法
using KnifeZ.Byeol.Views;
using System;
using System.Windows;
using System.Windows.Input;
namespace KnifeZ.TaskBarIcon
{
/// <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 = () => ChangeMainWindowState(WindowState.Normal),
};
}
}
/// <summary>
/// Hides the main window. This command is only enabled if a window is open.
/// </summary>
public ICommand HideWindowCommand
{
get
{
return new DelegateCommand
{
CommandAction = () => ChangeMainWindowState(WindowState.Minimized),
CanExecuteFunc = () => Application.Current.MainWindow != null
};
}
}
public void ChangeMainWindowState(WindowState state)
{
Application.Current.MainWindow.WindowState = state;
if (state == WindowState.Normal)
{
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Focus();
}
}
/// <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; }
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/walterwhiteHi/KnifeZ.Byeol.git
git@gitee.com:walterwhiteHi/KnifeZ.Byeol.git
walterwhiteHi
KnifeZ.Byeol
KnifeZ.Byeol
master

搜索帮助