AnnouncementMenuService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using GalaSoft.MvvmLight.Command;
  2. using Muchinfo.MTPClient.Account.Views;
  3. using Muchinfo.MTPClient.Data;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. using Muchinfo.MTPClient.Infrastructure.Helpers;
  6. using Muchinfo.MTPClient.IService;
  7. using System.Collections.Generic;
  8. using System.Windows;
  9. using System.Windows.Input;
  10. namespace Muchinfo.MTPClient.Account.ViewModels
  11. {
  12. /// <summary>
  13. /// 关于公告菜单的定义
  14. /// </summary>
  15. public class AnnouncementMenuService : IModuleMenuService
  16. {
  17. public Dictionary<Data.Enums.MenuCommandType, Data.SysMenuItem> GetModuleMenuItems()
  18. {
  19. var sysMenu = new Dictionary<MenuCommandType, SysMenuItem>();
  20. //公告通知
  21. sysMenu.Add(MenuCommandType.NoticeInform, new SysMenuItem(MenuCommandType.NoticeInform));
  22. //公告
  23. //sysMenu.Add(MenuCommandType.Notice, new SysMenuItem(MenuCommandType.Notice) { Command = MenuCommand, ViewType = typeof(SystemAnnouncementView), IsDialog = true });
  24. ////通知
  25. //sysMenu.Add(MenuCommandType.Notify, new SysMenuItem(MenuCommandType.Notify) { Command = MenuCommand, ViewType = typeof(SystemAnnouncementView), IsDialog = true });
  26. return sysMenu;
  27. }
  28. private ICommand _menuCommand;
  29. /// <summary>
  30. /// 菜单操作
  31. /// </summary>
  32. public ICommand MenuCommand
  33. {
  34. get
  35. {
  36. if (_menuCommand == null)
  37. {
  38. _menuCommand = new RelayCommand<SysMenuItem>((item) =>
  39. {
  40. if (!item.IsDialog)
  41. {
  42. var view = item.View as FrameworkElement;
  43. if (view != null)
  44. {
  45. MessengerHelper.DefaultSend(view, MessengerTokens.ShowQueryContet);
  46. }
  47. }
  48. else
  49. {
  50. var type = item.ViewType;
  51. var assembly = System.Reflection.Assembly.GetAssembly(type);
  52. var view = assembly.CreateInstance(type.FullName, false, System.Reflection.BindingFlags.CreateInstance, null, item.Params == null ? null : item.Params.ToArray(), null, null) as Window;
  53. if (view != null)
  54. {
  55. view.ShowDialog();
  56. }
  57. }
  58. });
  59. }
  60. return _menuCommand;
  61. }
  62. }
  63. }
  64. }