TradeParamSetView.xaml.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Interop;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using Muchinfo.MTPClient.Account.ViewModels;
  15. using Muchinfo.MTPClient.Data.Enums;
  16. using Muchinfo.MTPClient.Resources;
  17. namespace Muchinfo.MTPClient.Account.Views
  18. {
  19. /// <summary>
  20. /// TradeParamSetView.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class TradeParamSetView : Window
  23. {
  24. private TradeParamsSetViewModel viewModel = null;
  25. public TradeParamSetView()
  26. {
  27. InitializeComponent();
  28. this.DataContext = new TradeParamsSetViewModel();
  29. }
  30. /// <summary>
  31. /// 在这个方法执行的时候,可以获取到Style中元素的对象,这样我就可以给TradeTabControl注册时间
  32. /// </summary>
  33. public override void OnApplyTemplate()
  34. {
  35. base.OnApplyTemplate();
  36. TabControl tabControl = GetTemplateChild("TradeTabControl") as TabControl;
  37. if (tabControl != null)
  38. {
  39. tabControl.SelectionChanged += tabControl_SelectionChanged;
  40. }
  41. }
  42. /// <summary>
  43. /// tabControl 的选择事件
  44. /// </summary>
  45. /// <param name="sender"></param>
  46. /// <param name="e"></param>
  47. void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
  48. {
  49. InitViewModel();
  50. TabItem item = e.AddedItems[0] as TabItem;
  51. if (item != null && item.IsSelected && viewModel != null)
  52. {
  53. if (Client_Resource.TradeParamerSet_Title.Equals(item.Header))// 交易参数设置
  54. {
  55. viewModel.SettingTadIndex = SettingTadIndex.TRADE_SETTING;
  56. }
  57. else if (Client_Resource.Auto_Entrust_Profit_Loss.Equals(item.Header)) // 自动止盈止损
  58. {
  59. viewModel.SettingTadIndex = SettingTadIndex.TRADE_AUTO_ENTRUST;
  60. }
  61. }
  62. }
  63. private void InitViewModel()
  64. {
  65. if (viewModel == null)
  66. {
  67. viewModel = this.DataContext as TradeParamsSetViewModel;
  68. }
  69. }
  70. private void TextBoxBase_SP_OnTextChanged(object sender, TextChangedEventArgs e)
  71. {
  72. InitViewModel();
  73. int i = 0;
  74. if (int.TryParse((((TextBox)sender).Text), out i))
  75. {
  76. viewModel.SP_TextChanged.Execute(i);
  77. }
  78. }
  79. private void TextBoxBase_SL_OnTextChanged(object sender, TextChangedEventArgs e)
  80. {
  81. InitViewModel();
  82. int i = 0;
  83. if (int.TryParse((((TextBox)sender).Text), out i))
  84. {
  85. viewModel.SL_TextChanged.Execute(i);
  86. }
  87. }
  88. }
  89. }