SystemMenuTree.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using GalaSoft.MvvmLight.Ioc;
  3. using Muchinfo.MTPClient.Data;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. using Muchinfo.MTPClient.Infrastructure.Helpers;
  6. using Muchinfo.MTPClient.UI.ViewModels;
  7. using System.Windows.Controls;
  8. using System.Windows.Input;
  9. namespace Muchinfo.MTPClient.UI.Views
  10. {
  11. /// <summary>
  12. /// SystemMenuTree.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class SystemMenuTree : UserControl
  15. {
  16. private SysMenuItem _oldSysMenuItem = null;
  17. public SystemMenuTree()
  18. {
  19. InitializeComponent();
  20. // trees.InitTreeview();
  21. MessengerHelper.DefaultRegister<MenuCommandType>(this, MessengerTokens.MenuSelectChange, (menuCommand) =>
  22. {
  23. var viewModel= this.DataContext as MenuTreeViewModel;
  24. if (viewModel != null)
  25. {
  26. var menuItem= viewModel.FindSystemMenuItem(menuCommand);
  27. if (menuItem != null)
  28. {
  29. menuItem.IsSelected = true;
  30. TreeViewClick(menuItem);
  31. }
  32. }
  33. });
  34. this.Unloaded += SystemMenuTree_Unloaded;
  35. }
  36. void SystemMenuTree_Unloaded(object sender, System.Windows.RoutedEventArgs e)
  37. {
  38. MessengerHelper.DefaultUnregister(this);
  39. }
  40. private void TreeViewClick(SysMenuItem sysItem)
  41. {
  42. if (sysItem != null && sysItem.Command != null && sysItem.IsEnabled)
  43. {
  44. ////点击买入、卖出、撤单时,选中不变
  45. if (sysItem.SysCommandType == MenuCommandType.BuyIn || sysItem.SysCommandType == MenuCommandType.Sellout || sysItem.SysCommandType == MenuCommandType.Cancel)
  46. {
  47. sysItem.IsSelected = false;
  48. if (_oldSysMenuItem != null) _oldSysMenuItem.IsSelected = true;
  49. }
  50. else
  51. {
  52. _oldSysMenuItem = sysItem;
  53. }
  54. sysItem.Command.Execute(sysItem);
  55. }
  56. }
  57. private void TreeView_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  58. {
  59. TreeViewClick( FunctionTreeView.SelectedItem as SysMenuItem);
  60. }
  61. }
  62. }