using System;
using System.Windows.Input;
using Muchinfo.MTPClient.Analysis.ViewModels;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Infrastructure.Interfaces;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using System.Windows;
using System.Windows.Forms;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using UserControl = System.Windows.Controls.UserControl;
namespace Muchinfo.MTPClient.Analysis.Views
{
///
/// CChartView.xaml 的交互逻辑
///
public partial class CChartView : UserControl, IDisposable
{
public CChartView(ChartWindowItem chartItem)
{
InitializeComponent();
var userControl = new System.Windows.Forms.ListView();
// userControl.BackColor = System.Drawing.Color.Transparent;
var colorStyle = UserManager.GetCurrentColorStyle();
switch (colorStyle)
{
case ColorStyle.BlueWhite:
userControl.BackColor = System.Drawing.Color.White;
break;
case ColorStyle.DarkBlue:
case ColorStyle.CoolBlack:
userControl.BackColor = System.Drawing.Color.Black;
break;
default:
break;
}
userControl.BorderStyle = BorderStyle.None;
FormsHost.Child = userControl;
var handle = userControl.Handle.ToInt32();
var goods = chartItem.Goods;
this.DataContext = new CChartViewModel(goods, handle);
// _currentGoods = goods;
// _quoteDataService = SimpleIoc.Default.GetInstance();
// WareAttributeClass war = ConverWare(goods);
// this.m_Ware = war;
//// QuoteChartManager.AddWare(this.Ware);
// AddWare(war);
// CreateChartView(_currentGoods);
//MessengerHelper.DefaultRegister(this, MessengerTokens.QuoteGoodsListToken, (msg) =>
//{
// var viewModel = this.DataContext as CChartViewModel;
// if (viewModel == null)
// {
// return;
// }
// if (this.IsKeyboardFocusWithin)
// {
// switch (msg)
// {
// case CommandFunc.QuotePageDown:
// viewModel.ChangeGoodsNextFront(true);
// break;
// case CommandFunc.QuotePageup:
// viewModel.ChangeGoodsNextFront(false);
// break;
// }
// }
//});
}
private void CChartView_OnUnloaded(object sender, RoutedEventArgs e)
{
this.InputBindings.Clear();
// var dataContext = this.DataContext as CChartViewModel;
//if (dataContext != null)
//{
// dataContext.Dispose();
//}
}
public void Dispose()
{
this.InputBindings.Clear();
TabPriceView.Dispose();
}
private void CChartView_OnLoaded(object sender, RoutedEventArgs e)
{
FormsHost.Focusable = true;
FormsHost.Focus();
}
private void FormsHost_OnKeyUp(object sender, KeyEventArgs e)
{
var dataContext = this.DataContext as CChartViewModel;
if (dataContext != null)
{
if (e.Key == Key.PageDown || e.Key == Key.PageUp)
{
dataContext.EnterCommand.Execute(e.Key);
}
}
}
private void FormsHost_OnLoaded(object sender, RoutedEventArgs e)
{
FormsHost.Focus();
}
}
}