| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.UI.ViewModels;
- using System.Windows.Controls;
- using System.Windows.Input;
- namespace Muchinfo.MTPClient.UI.Views
- {
- /// <summary>
- /// SystemMenuTree.xaml 的交互逻辑
- /// </summary>
- public partial class SystemMenuTree : UserControl
- {
- private SysMenuItem _oldSysMenuItem = null;
- public SystemMenuTree()
- {
- InitializeComponent();
-
- // trees.InitTreeview();
- MessengerHelper.DefaultRegister<MenuCommandType>(this, MessengerTokens.MenuSelectChange, (menuCommand) =>
- {
- var viewModel= this.DataContext as MenuTreeViewModel;
- if (viewModel != null)
- {
- var menuItem= viewModel.FindSystemMenuItem(menuCommand);
- if (menuItem != null)
- {
- menuItem.IsSelected = true;
- TreeViewClick(menuItem);
- }
- }
- });
- this.Unloaded += SystemMenuTree_Unloaded;
- }
- void SystemMenuTree_Unloaded(object sender, System.Windows.RoutedEventArgs e)
- {
- MessengerHelper.DefaultUnregister(this);
- }
-
- private void TreeViewClick(SysMenuItem sysItem)
- {
- if (sysItem != null && sysItem.Command != null && sysItem.IsEnabled)
- {
- ////点击买入、卖出、撤单时,选中不变
- if (sysItem.SysCommandType == MenuCommandType.BuyIn || sysItem.SysCommandType == MenuCommandType.Sellout || sysItem.SysCommandType == MenuCommandType.Cancel)
- {
- sysItem.IsSelected = false;
- if (_oldSysMenuItem != null) _oldSysMenuItem.IsSelected = true;
- }
- else
- {
- _oldSysMenuItem = sysItem;
- }
- sysItem.Command.Execute(sysItem);
- }
- }
- private void TreeView_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- TreeViewClick( FunctionTreeView.SelectedItem as SysMenuItem);
- }
- }
- }
|