外贸soho做网站怎么做,展示网站报价,免费企业网站制作,男人和女人一起对愁愁的说话1、在项目中用nuget引入Hardcodet.NotifyIcon.Wpf。如下图所示。
2、在App.xaml中创建托盘界面#xff0c;代码是写在 App.xaml 里面
注意在application中一定要加入这一行代码#xff1a; xmlns:tbhttp://www.hardcodet.net/taskbar
然后在Application.R…1、在项目中用nuget引入Hardcodet.NotifyIcon.Wpf。如下图所示。
2、在App.xaml中创建托盘界面代码是写在 App.xaml 里面
注意在application中一定要加入这一行代码 xmlns:tbhttp://www.hardcodet.net/taskbar
然后在Application.Resources中加入如下代码 Application.ResourcesContextMenu x:Sharedfalse x:KeySysTrayMenuMenuItem Height25 Header显示界面 Command{Binding NotifyCommand} CommandParameter1/MenuItemMenuItem Height25 Header隐藏界面 Command{Binding NotifyCommand} CommandParameter0/MenuItemSeparator /MenuItem Height25 Header退出服务 Command{Binding NotifyCommand} CommandParameter99/MenuItem/ContextMenutb:TaskbarIcon x:KeyTaskbar ToolTipTextDoubleClickCommand{Binding NotifyCommand} DoubleClickCommandParameter1ContextMenu{StaticResource SysTrayMenu} IconSource/jqsw.icotb:TaskbarIcon.TrayToolTipBorder BackgroundLightYellow CornerRadius5 Opacity0.8 Padding10StackPanel OrientationVerticalTextBlock Text温湿度数据采集服务网口版 ForegroundRed/!--TextBlock Text{Binding SystemTime} ForegroundRed/--/StackPanel/Border/tb:TaskbarIcon.TrayToolTip/tb:TaskbarIcon/Application.Resources
3、创建ViewModelBase类。再创建TaskbarIconViewModel类继承ViewModelBase类
internal class ViewModelBase : INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged ;protected void RaisePropertyChanged(string property){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));}}internal class TaskbarIconViewModel : ViewModelBase{private string systemTime;public string SystemTime{get { return systemTime; }set { systemTime value; RaisePropertyChanged(SystemTime); }}public DelegateCommand NotifyCommand{get{return new DelegateCommand((type) {if (type.ToString() 0)Application.Current.MainWindow.Hide();if (type.ToString() 1){Application.Current.MainWindow.Show();Application.Current.MainWindow.Activate();}if (type.ToString() 99)Application.Current.Shutdown();});}}}
、在App.xaml.cs中写入如下代码
private static System.Threading.Mutex mutex;protected override void OnStartup(StartupEventArgs e){mutex new System.Threading.Mutex(true, TemCollSrvTwo);if (mutex.WaitOne(0, false)){base.OnStartup(e);}else{MessageBox.Show(程序已经在运行, 提示);this.Shutdown();} mTaskbarIcon (TaskbarIcon)FindResource(Taskbar);mTaskbarIcon.DataContext new TaskbarIconViewModel();}public static TaskbarIcon mTaskbarIcon;4031
5、效果展示