using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Muchinfo.MTPClient.Account.ViewModels;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Resources;
namespace Muchinfo.MTPClient.Account.Views
{
///
/// TradeParamSetView.xaml 的交互逻辑
///
public partial class TradeParamSetView : Window
{
private TradeParamsSetViewModel viewModel = null;
public TradeParamSetView()
{
InitializeComponent();
this.DataContext = new TradeParamsSetViewModel();
}
///
/// 在这个方法执行的时候,可以获取到Style中元素的对象,这样我就可以给TradeTabControl注册时间
///
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
TabControl tabControl = GetTemplateChild("TradeTabControl") as TabControl;
if (tabControl != null)
{
tabControl.SelectionChanged += tabControl_SelectionChanged;
}
}
///
/// tabControl 的选择事件
///
///
///
void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
InitViewModel();
TabItem item = e.AddedItems[0] as TabItem;
if (item != null && item.IsSelected && viewModel != null)
{
if (Client_Resource.TradeParamerSet_Title.Equals(item.Header))// 交易参数设置
{
viewModel.SettingTadIndex = SettingTadIndex.TRADE_SETTING;
}
else if (Client_Resource.Auto_Entrust_Profit_Loss.Equals(item.Header)) // 自动止盈止损
{
viewModel.SettingTadIndex = SettingTadIndex.TRADE_AUTO_ENTRUST;
}
}
}
private void InitViewModel()
{
if (viewModel == null)
{
viewModel = this.DataContext as TradeParamsSetViewModel;
}
}
private void TextBoxBase_SP_OnTextChanged(object sender, TextChangedEventArgs e)
{
InitViewModel();
int i = 0;
if (int.TryParse((((TextBox)sender).Text), out i))
{
viewModel.SP_TextChanged.Execute(i);
}
}
private void TextBoxBase_SL_OnTextChanged(object sender, TextChangedEventArgs e)
{
InitViewModel();
int i = 0;
if (int.TryParse((((TextBox)sender).Text), out i))
{
viewModel.SL_TextChanged.Execute(i);
}
}
}
}