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.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Aitex.UI.Charting.ViewModel; using Aitex.UI.Charting.Model; namespace Aitex.UI.Charting.View { /// /// Interaction logic for DataSourceView.xaml /// public partial class DataSourceView : UserControl { public DataSourceView() { InitializeComponent(); Loaded += new RoutedEventHandler(DataSourceView_Loaded); _viewModel = new DataSourceViewModel(); DataContext = _viewModel; } DataSourceViewModel _viewModel; void DataSourceView_Loaded(object sender, RoutedEventArgs e) { //_viewModel = new DataSourceViewModel(); //DataContext = _viewModel; } /// /// DataGrid的SelectionChange不支持ICommand接口,此处采用message handling方式处理 /// /// /// private void DataSource_SelectionChanged(object sender, SelectionChangedEventArgs e) { if(dataGrid_DataSources.SelectedItem != null) { CommonViewModel.Instance.CurrentSelectedDataSource = (IDataSource)dataGrid_DataSources.SelectedItem; } } #if false /// /// Template模板中的事件不能通过ICommand绑定 /// /// /// private void DataSource_SyncTime(object sender, SelectionChangedEventArgs e) { if (sender is ComboBox) { var combo = (ComboBox)sender; var selection = combo.SelectedItem as RecipeSyncPoint; string sourceName = (string)((ComboBox)sender).Tag; _viewModel.SyncSourceTimeCommand.Execute(new Tuple(sourceName, selection.StepTime, selection.StepName)); } } #endif private void DataSource_Export(object sender, RoutedEventArgs e) { string sourceName = (string)((Button)sender).Tag; Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = sourceName.Replace("/", "_").Replace(":", "_").Replace(" ", "_"); // Default file name dlg.DefaultExt = ".arch"; // Default file extension dlg.Filter = "Archive File (.arch)|*.arch"; // Filter files by extension // Show open file dialog box Nullable result = dlg.ShowDialog(); if (result.HasValue && result.Value) { DataSourceExportingDialog processDialog = new DataSourceExportingDialog(sourceName, dlg.FileName) { Owner = Application.Current.MainWindow }; processDialog.Show(); } } private void DataSource_Remove(object sender, RoutedEventArgs e) { var sourceName = (string)((Button)sender).Tag; CommonViewModel.Instance.RemoveDataSource(sourceName); } } }