using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.Trade.ViewModels; using Muchinfo.MTPClient.Trade.ViewModels.Unified; namespace Muchinfo.MTPClient.Trade.Views { /// /// EntrustOrderView.xaml 的交互逻辑 /// public partial class EntrustOrderView : Window { public EntrustOrderView(QuoteGoods goods, Direction direction ) { InitializeComponent(); this.DataContext = new TradeOrderViewModel(goods, direction); InitView(); DeliveryPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(DeliveryPopupPlacementCallback); MessengerHelper.DefaultRegister(this, MessengerTokens.SetButtonFoucsToken, (result) => { btnOKCommand.Focus(); }); } public EntrustOrderView(OrderBase orderBase,ePriceMode orderPriceMode) { InitializeComponent(); this.DataContext = new TradeOrderViewModel(orderBase, orderPriceMode); InitView(); DeliveryPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(DeliveryPopupPlacementCallback); MessengerHelper.DefaultRegister(this, MessengerTokens.SetButtonFoucsToken, (result) => { btnOKCommand.Focus(); }); } private void InitView() { var viewModel = this.DataContext as TradeOrderViewModel; if (!ApplicationParameter.ShowBuyOrSellPrice && viewModel != null && viewModel.OrderModel == OrderModel.Normal) { var width = MinWidth - 200; MinWidth = width; Width = width; viewModel.ShowOkCancel = false; } else { if (viewModel != null && viewModel.OrderModel == OrderModel.SPSL) { viewModel.ShowOkCancel = true; } } } public EntrustOrderView(TradeOrderViewModel OrderViewModel) { InitializeComponent(); this.DataContext = OrderViewModel; InitView(); DeliveryPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(DeliveryPopupPlacementCallback); MessengerHelper.DefaultRegister(this, MessengerTokens.SetButtonFoucsToken, (result) => { btnOKCommand.Focus(); }); } protected override void OnClosed(EventArgs e) { base.OnClosed(e); MessengerHelper.DefaultUnregister(this, MessengerTokens.SetButtonFoucsToken); } private void openOrderWindow_Closed(object sender, EventArgs e) { if(this.DataContext is TradeOrderViewModel) { (this.DataContext as TradeOrderViewModel).Cleanup(); } } private CustomPopupPlacement[] DeliveryPopupPlacementCallback(Size popupSize, Size targetSize, Point offset) { DeliveryPopup.Height = this.ActualHeight - 20; CustomPopupPlacement hPlacement = new CustomPopupPlacement(new Point(this.ActualWidth - 10,10), PopupPrimaryAxis.Horizontal); CustomPopupPlacement vPlacement = new CustomPopupPlacement(new Point(-260, 10), PopupPrimaryAxis.Vertical); CustomPopupPlacement[] placements = new CustomPopupPlacement[] { hPlacement ,vPlacement}; return placements; } //private void openOrderWindow_MouseMove(object sender, MouseEventArgs e) //{ // Point p = e.MouseDevice.GetPosition(this); // var pp = this.DeliveryPopup.PointToScreen(p); // if (pp.Y < this.DeliveryPopup.Height) // { // this.DeliveryPopup.IsOpen = false; // } //} } }