improved notifyicon

added mouseenter and mouseleave events
This commit is contained in:
NaBian committed 2019-04-20 23:36:44 +08:00
1 parent 9aa6df87cb
commit 3aa0f09d39
6 files changed
+388 -16

No files matched your search

@@ -1,15 +1,31 @@
using System;
using System.Collections.Generic;
namespace HandyControlDemo.Tools
{
public class AssemblyHelper
internal class AssemblyHelper
{
private static readonly string NameSpaceStr = typeof(AssemblyHelper).Assembly.GetName().Name;
private static readonly Dictionary<string, object> CacheDic = new Dictionary<string, object>();
public static void Register(string name, object instance) => CacheDic[name] = instance;
public static object ResolveByKey(string key)
{
if (CacheDic.TryGetValue(key, out var value))
{
return value;
}
return null;
}
public static object CreateInternalInstance(string className)
{
try
{
var type = Type.GetType($"{NameSpaceStr}.{className}");
return type == null ? null : Activator.CreateInstance(type);
}
@@ -1,4 +1,6 @@
using System.Windows;
using HandyControlDemo.Tools;
using HandyControlDemo.ViewModel;
namespace HandyControlDemo.UserControl
{
@@ -7,8 +9,13 @@ namespace HandyControlDemo.UserControl
public NotifyIconDemoCtl()
{
InitializeComponent();
AssemblyHelper.Register(nameof(NotifyIconDemoCtl), this);
Unloaded += NotifyIconDemoCtl_Unloaded;
}
private void NotifyIconDemoCtl_Unloaded(object sender, RoutedEventArgs e) => ViewModelLocator.Instance.NotifyIconDemo.Cleanup();
private void ButtonPush_OnClick(object sender, RoutedEventArgs e) => NotifyIconContextContent.CloseContextControl();
}
}
@@ -12,6 +12,10 @@ namespace HandyControlDemo.ViewModel
{
public class NotifyIconDemoViewModel : ViewModelBase
{
private bool _isCleanup;
private bool _reversed;
private bool _contextMenuIsShow;
public bool ContextMenuIsShow
@@ -25,6 +29,12 @@ namespace HandyControlDemo.ViewModel
Set(ref _contextMenuIsShow, value);
#endif
GlobalData.NotifyIconIsShow = ContextMenuIsShow || ContextContentIsShow;
if (!_isCleanup && !_reversed)
{
_reversed = true;
ContextContentIsShow = !value;
_reversed = false;
}
}
}
@@ -53,6 +63,12 @@ namespace HandyControlDemo.ViewModel
Set(ref _contextContentIsShow, value);
#endif
GlobalData.NotifyIconIsShow = ContextMenuIsShow || ContextContentIsShow;
if (!_isCleanup && !_reversed)
{
_reversed = true;
ContextMenuIsShow = !value;
_reversed = false;
}
}
}
@@ -70,5 +86,18 @@ namespace HandyControlDemo.ViewModel
public RelayCommand<object> MouseCmd => new Lazy<RelayCommand<object>>(() =>
new RelayCommand<object>(str=> Growl.Info(str.ToString()))).Value;
public override void Cleanup()
{
base.Cleanup();
_isCleanup = true;
ContextMenuIsShow = false;
ContextMenuIsBlink = false;
ContextContentIsShow = false;
ContextContentIsBlink = false;
GlobalData.NotifyIconIsShow = false;
_isCleanup = false;
}
}
}
@@ -82,7 +82,7 @@ namespace HandyControlDemo.ViewModel
#endregion
#region 命令
#region 命令
/// <summary>
/// 切换例子命令
@@ -109,7 +109,8 @@ namespace HandyControlDemo.ViewModel
_listBoxItemCurrent = item;
ContentTitle = item.Content;
Messenger.Default.Send(false, MessageToken.FullSwitch);
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{tag}"), MessageToken.LoadShowContent);
var obj = AssemblyHelper.ResolveByKey(tag);
Messenger.Default.Send(obj ?? AssemblyHelper.CreateInternalInstance($"UserControl.{tag}"), MessageToken.LoadShowContent);
}
else
{