EntrustOrderView.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.Controls.Primitives;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. using Muchinfo.MTPClient.Data.Enums;
  15. using Muchinfo.MTPClient.Data.Model;
  16. using Muchinfo.MTPClient.Data.Model.Account;
  17. using Muchinfo.MTPClient.Infrastructure.Helpers;
  18. using Muchinfo.MTPClient.Infrastructure.Utilities;
  19. using Muchinfo.MTPClient.Trade.ViewModels;
  20. using Muchinfo.MTPClient.Trade.ViewModels.Unified;
  21. namespace Muchinfo.MTPClient.Trade.Views
  22. {
  23. /// <summary>
  24. /// EntrustOrderView.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class EntrustOrderView : Window
  27. {
  28. public EntrustOrderView(QuoteGoods goods, Direction direction )
  29. {
  30. InitializeComponent();
  31. this.DataContext = new TradeOrderViewModel(goods, direction);
  32. InitView();
  33. DeliveryPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(DeliveryPopupPlacementCallback);
  34. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.SetButtonFoucsToken, (result) =>
  35. {
  36. btnOKCommand.Focus();
  37. });
  38. }
  39. public EntrustOrderView(OrderBase orderBase,ePriceMode orderPriceMode)
  40. {
  41. InitializeComponent();
  42. this.DataContext = new TradeOrderViewModel(orderBase, orderPriceMode);
  43. InitView();
  44. DeliveryPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(DeliveryPopupPlacementCallback);
  45. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.SetButtonFoucsToken, (result) =>
  46. {
  47. btnOKCommand.Focus();
  48. });
  49. }
  50. private void InitView()
  51. {
  52. var viewModel = this.DataContext as TradeOrderViewModel;
  53. if (!ApplicationParameter.ShowBuyOrSellPrice &&
  54. viewModel != null &&
  55. viewModel.OrderModel == OrderModel.Normal)
  56. {
  57. var width = MinWidth - 200;
  58. MinWidth = width;
  59. Width = width;
  60. viewModel.ShowOkCancel = false;
  61. }
  62. else
  63. {
  64. if (viewModel != null &&
  65. viewModel.OrderModel == OrderModel.SPSL)
  66. {
  67. viewModel.ShowOkCancel = true;
  68. }
  69. }
  70. }
  71. public EntrustOrderView(TradeOrderViewModel OrderViewModel)
  72. {
  73. InitializeComponent();
  74. this.DataContext = OrderViewModel;
  75. InitView();
  76. DeliveryPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(DeliveryPopupPlacementCallback);
  77. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.SetButtonFoucsToken, (result) =>
  78. {
  79. btnOKCommand.Focus();
  80. });
  81. }
  82. protected override void OnClosed(EventArgs e)
  83. {
  84. base.OnClosed(e);
  85. MessengerHelper.DefaultUnregister<bool>(this, MessengerTokens.SetButtonFoucsToken);
  86. }
  87. private void openOrderWindow_Closed(object sender, EventArgs e)
  88. {
  89. if(this.DataContext is TradeOrderViewModel)
  90. {
  91. (this.DataContext as TradeOrderViewModel).Cleanup();
  92. }
  93. }
  94. private CustomPopupPlacement[] DeliveryPopupPlacementCallback(Size popupSize, Size targetSize, Point offset)
  95. {
  96. DeliveryPopup.Height = this.ActualHeight - 20;
  97. CustomPopupPlacement hPlacement = new CustomPopupPlacement(new Point(this.ActualWidth - 10,10), PopupPrimaryAxis.Horizontal);
  98. CustomPopupPlacement vPlacement = new CustomPopupPlacement(new Point(-260, 10), PopupPrimaryAxis.Vertical);
  99. CustomPopupPlacement[] placements = new CustomPopupPlacement[] { hPlacement ,vPlacement};
  100. return placements;
  101. }
  102. //private void openOrderWindow_MouseMove(object sender, MouseEventArgs e)
  103. //{
  104. // Point p = e.MouseDevice.GetPosition(this);
  105. // var pp = this.DeliveryPopup.PointToScreen(p);
  106. // if (pp.Y < this.DeliveryPopup.Height)
  107. // {
  108. // this.DeliveryPopup.IsOpen = false;
  109. // }
  110. //}
  111. }
  112. }