protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            System.Diagnostics.Debug.WriteLine(string.Format("Start analysis:{0}", DateTime.Now));

            Task<IEnumerable<FlightDataEntitiesRT.Charts.ChartPanel>> task = Task.Run<
                IEnumerable<FlightDataEntitiesRT.Charts.ChartPanel>>(
                new Func<IEnumerable<FlightDataEntitiesRT.Charts.ChartPanel>>(delegate()
            {
                var panels = ApplicationContext.Instance.GetChartPanels(ApplicationContext.Instance.CurrentAircraftModel);
                return panels;
            }));

            //要处理别的地方导航过来的
            if (e.Parameter != null && e.Parameter is AircraftDataAnalysisWinRT.Common.DecisionWrap)
            {
                DecisionRecordFlightAnalysisViewModel viewModel1 = new DecisionRecordFlightAnalysisViewModel(
                    e.Parameter as AircraftDataAnalysisWinRT.Common.DecisionWrap);
                this.DataContext = viewModel1;
                m_viewModel = viewModel1;
                // this.grdCtrl.ViewModel = viewModel1;
                BindDataCore();
                return;
            }
            else if (e.Parameter != null && e.Parameter is ExtremumReportItemWrap)
            {
                ExtremumInfoFlightAnalysisViewModel viewModel2 = new ExtremumInfoFlightAnalysisViewModel(
                    e.Parameter as ExtremumReportItemWrap);
                this.DataContext = viewModel2;
                m_viewModel = viewModel2;
                // this.grdCtrl.ViewModel = viewModel2;
                BindDataCore();
                return;
            }
            //处理别的地方导航过来的

            PanelChangedWrap wrapPanel = null;
            if (e.Parameter != null && e.Parameter is PanelChangedWrap
               && (e.Parameter as PanelChangedWrap).SelectedPanel != null)
            {
                wrapPanel = e.Parameter as PanelChangedWrap;
            }

            await NavigationToPanel(task, wrapPanel);
        }
        internal static IEnumerable<XamDataChart> BuildChartElements(FlightAnalysisViewModel viewModel,
            IEnumerable<string> parameterIDs, ref FAChartModel faChartModel)
        {
            List<XamDataChart> charts = new List<XamDataChart>();
            IEnumerable<AxisDataBindingObject> bindingObjs = CalculateBindingObjects(viewModel, parameterIDs);

            foreach (var bd in bindingObjs)
            {
                var chartCtrl = BindingChartUIFactory.CreateOneChart(bd, ref faChartModel);
                if (chartCtrl != null)
                {
                    if (chartCtrl != null)
                        charts.Add(chartCtrl);

                    //TODO: custom chart event handle:

                }
            }

            return charts;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter == null || !(e.Parameter is GridDataDisplayArg))
            {
                return;
            }

            base.OnNavigatedTo(e);

            this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                new Windows.UI.Core.DispatchedHandler(
                    delegate()
                    {
                        GridDataDisplayArg arg = e.Parameter as GridDataDisplayArg;

                        this.m_viewModel = arg.ViewModel;
                        this.ReBindColumns(arg.ParameterIDs);
                        this.sfDataPager.Source = this.ToSubset(
                            m_viewModel.RawDatas, arg.StartSecond, arg.EndSecond);
                    }));
        }
        private static IEnumerable<AxisDataBindingObject> CalculateBindingObjects(FlightAnalysisViewModel viewModel,
            IEnumerable<string> parameterIds)
        {
            if (parameterIds != null)
            {
                //var result1 = from one in parameterIds
                //              where one.IsChecked
                //              select one;

                //KG(开关量)分一组
                //T6L、T6R分一组
                //NHL、NHR分一组

                List<AxisDataBindingObject> objs = new List<AxisDataBindingObject>();

                Dictionary<string, AxisDataBindingObject> objMap
                    = new Dictionary<string, AxisDataBindingObject>();

                int item = 0;
                foreach (var res in parameterIds)
                {
                    string key = res;
                    if (res.StartsWith("KG"))
                    {
                        key = "KG";
                    }
                    else if (res.StartsWith("T6"))
                    {
                        key = "T6";
                    }
                    else if (res.StartsWith("NH"))
                    {
                        key = "NH";
                    }
                    if (objMap.ContainsKey(key))
                    {
                        objMap[key].AddRelatedParameterID(res);
                        continue;
                    }
                    else
                    {
                        AxisDataBindingObject obj = new AxisDataBindingObject(viewModel);
                        if (key == "KG")
                        {
                            obj = new KGAxisDataBindingObject(viewModel);
                        }
                        else if (key == "T6")
                        {
                            obj = new T6AxisDataBindingObject(viewModel);
                        }
                        else if (key == "NH")
                        {
                            obj = new NHAxisDataBindingObject(viewModel);
                        }
                        obj.ParameterID = key;
                        obj.Order = item;
                        item++;
                        obj.AddRelatedParameterID(res);

                        objMap.Add(key, obj);
                        objs.Add(obj);
                    }
                }

                var result2 = from ob in objs
                              orderby ob.Order ascending
                              select ob;

                return result2;
            }

            return new AxisDataBindingObject[] { };
        }
 public T6AxisDataBindingObject(FlightAnalysisViewModel viewModel)
     : base(viewModel)
 {
 }
 public AxisDataBindingObject(FlightAnalysisViewModel viewModel)
 {
     this.viewModel = viewModel;
 }
 public RelatedParameterViewModel(FlightAnalysisViewModel viewModel, FlightParameter para)
 {
     this.viewModel = viewModel;
     this.m_parameter = para;
 }
        private async Task NavigationToPanel(Task<IEnumerable<FlightDataEntitiesRT.Charts.ChartPanel>> task,
            PanelChangedWrap wrapPanel)
        {
            string panelID = string.Empty;
            FlightAnalysisViewModel viewModel = new FlightAnalysisViewModel()
            {
                CurrentStartSecond = ApplicationContext.Instance.CurrentFlight.StartSecond,
                CurrentEndSecond = ApplicationContext.Instance.CurrentFlight.EndSecond
            };

            if (wrapPanel != null)
            {
                panelID = wrapPanel.SelectedPanel.PanelID;
            }
            else
            {
                viewModel.CurrentStartSecond = 0;
                viewModel.CurrentEndSecond = ApplicationContext.Instance.CurrentFlight.EndSecond;
            }
            //要么是没有选择ID的,那就是第一个Panel
            var panels2 = await task;
            System.Diagnostics.Debug.WriteLine(string.Format("Flight Analysis Model Created:{0}", DateTime.Now));
            this.tabHost.Items.Clear();
            //create tabs
            if (panels2 != null && panels2.Count() > 0)
            {
                foreach (var pan in panels2)
                {
                    var content = new AircraftDataAnalysisWinRT.MyControl.FAChart()
                               {
                                   DataContext = viewModel,
                                   ViewModel = viewModel,
                               };
                    content.FlightAnalysisSubNavigationRequested += content_FlightAnalysisSubNavigationRequested;
                    SfTabItem item = new SfTabItem()
                    {
                        Header = pan.PanelName,
                        Content = content,
                        //new ScrollViewer()
                        //{
                        //    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                        //    HorizontalScrollMode = ScrollMode.Disabled,
                        //    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                        //    VerticalScrollMode = ScrollMode.Auto,
                        //    Content =

                        //}
                    };
                    item.DoubleTapped += item_DoubleTapped;
                    item.Name = pan.PanelID;
                    this.tabHost.Items.Add(item);
                }
            }


            //开始注意消息循环了,最后才绑定viewModel;
            //m_viewModel = viewModel;
            if (string.IsNullOrEmpty(panelID))
            {
                System.Diagnostics.Debug.Assert(panels2 != null && panels2.Count() > 0
                    && panels2.First() != null);
                panelID = panels2.First().PanelID;
            }
            //如果还是空,则直接Return
            if (string.IsNullOrEmpty(panelID))
                return;
            m_viewModel = viewModel;

            SetSelectedPanel(panelID);
            //m_viewModel.RefreshAndRetriveData();

            //this.chartTest.SubViewModel = new FlightAnalysisSubViewModel() = m_viewModel;
            return;

            //debug

            //TODO: rebuild bindingPanel
            /*
            this.cbPanelSelect.ItemsSource = panels2;
            int index = this.GetPanelSelectedIndex(panels2, panelID);
            m_switcher = true;
            this.cbPanelSelect.SelectedIndex = index;
            m_switcher = false;
            viewModel.CurrentPanel = panels2.ElementAt(index);
            m_viewModel = viewModel;*/
            //this.grdCtrl.ViewModel = m_viewModel;
            //this.grdCtrl.ReBindColumns();
            BindDataCore();
        }
        private string[] SelectedIds(FlightAnalysisViewModel viewModel)
        {
            var result = from one in viewModel.RelatedParameterCollection
                         where one.IsChecked
                         select one.Parameter.ParameterID;

            return result.ToArray();
        }
 public RelatedParameterViewModel(FlightAnalysisViewModel viewModel, bool isChecked, FlightParameter para)
 {
     this.viewModel = viewModel;
     this.m_isChecked = isChecked;
     this.m_parameter = para;
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
                return;
            System.Diagnostics.Debug.WriteLine(string.Format("Start trend chart:{0}", DateTime.Now));
            base.OnNavigatedTo(e);

            FlightAnalysisViewModel viewModel = new FlightAnalysisViewModel();
            var panels = ApplicationContext.Instance.GetChartPanels(ApplicationContext.Instance.CurrentAircraftModel);

            viewModel.CurrentStartSecond = 0;
            viewModel.CurrentEndSecond = ApplicationContext.Instance.CurrentFlight.EndSecond;
            m_viewModel = viewModel;
            m_viewModel.RelatedParameterCollection = this.GetRelateds();
            m_viewModel.RefreshAndRetriveData();
            this.DataContext = m_viewModel;

            m_viewModel.RefreshAndRetriveData();
            System.Diagnostics.Debug.WriteLine(string.Format("before trend chart bind:{0}", DateTime.Now));
            //var dts = this.GetRawDatas(m_viewModel.GridData);

            //this.sfchart.Series["Hp"].ItemsSource = dts;
            //this.sfchart.Series["Vi"].ItemsSource = dts;
            //this.sfchart.Series["T6L"].ItemsSource = dts;
            //this.sfchart.Series["T6R"].ItemsSource = dts;

            //this.sfchart.DataContext = m_viewModel.EntityData;
            System.Diagnostics.Debug.WriteLine(string.Format("end trend chart:{0}", DateTime.Now));
        }