| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- using MahApps.Metro.Controls;
- using MaterialDesignThemes.Wpf;
- using NPOI.SS.Formula.Functions;
- using OxyPlot;
- using OxyPlot.Axes;
- using OxyPlot.Legends;
- using OxyPlot.Series;
- using OxyPlot.Wpf;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Ioc;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media;
- using TeamAAS_VP;
- using TeamAAS_VP.Controls;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Data;
- using TeamAAS_VP.Enums;
- using TeamAAS_VP.Events;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP.Resources.Languages;
- using TeamAAS_VP.Services;
- using TeamAAS_VP.ViewModels.DebugMod;
- using TeamAAS_VP.Views.DebugMod;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
- namespace TeamAAS_VP.ViewModels
- {
- public class HomeViewModel : BindableBase, IConfirmNavigationRequest
- {
- IEventAggregator _eventAggregator;
- IContainerProvider _container;
- IProductService _productService;
- IConfigService _configService;
- IRemoteCommandService _remoteCommandService;
- ISystemDatabaseService _systemDatabaseService;
- IDialogService _dialogService;
- #region 属性
- private PlotModel _PressurePlotModel = new PlotModel();
- /// <summary>
- /// 每个元素是一个 PlotModel,对应一个压力传感器
- /// </summary>
- public PlotModel PressurePlotModel
- {
- get { return _PressurePlotModel; }
- set { SetProperty(ref _PressurePlotModel, value); }
- }
- private ObservableCollection<TaskMessage> messageQueue = new ObservableCollection<TaskMessage>();
- /// <summary>
- /// 运行信息队列
- /// </summary>
- public ObservableCollection<TaskMessage> MessageQueue
- {
- get { return messageQueue; }
- set { SetProperty(ref messageQueue, value); }
- }
- private ObservableCollection<ProductModel> _ProductList;
- public ObservableCollection<ProductModel> ProductList
- {
- get { return _ProductList; }
- set { SetProperty(ref _ProductList, value); }
- }
- private Management _management;
- public Management management
- {
- get { return _management; }
- set { SetProperty(ref _management, value); }
- }
- private double _CTTotalSeconds;
- public double CTTotalSeconds
- {
- get { return _CTTotalSeconds; }
- set { SetProperty(ref _CTTotalSeconds, value); }
- }
- private ProductModel _SelectProduct;
- public ProductModel SelectProduct
- {
- get { return _SelectProduct; }
- set { SetProperty(ref _SelectProduct, value); }
- }
- private bool CanLoad
- {
- get
- {
- if (SelectProduct != null && IsLoadProduct)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- private bool _IsLoadProduct = true;
- public bool IsLoadProduct
- {
- get { return _IsLoadProduct; }
- set { SetProperty(ref _IsLoadProduct, value); }
- }
- private bool _isCanExecute = true;
- public bool isCanExecute
- {
- get { return _isCanExecute; }
- set { SetProperty(ref _isCanExecute, value); }
- }
- private ProductModel _CurrentProduct;
- public ProductModel CurrentProduct
- {
- get { return _CurrentProduct; }
- set { SetProperty(ref _CurrentProduct, value); }
- }
- private PlotModel _LockCurvePlotModel;
- /// <summary>
- /// 锁付曲线
- /// </summary>
- public PlotModel LockCurvePlotModel
- {
- get { return _LockCurvePlotModel; }
- set { SetProperty(ref _LockCurvePlotModel, value); }
- }
- private ObservableCollection<LockResult> _LockResults = new ObservableCollection<LockResult>();
- /// <summary>
- /// 锁付结果列表
- /// </summary>
- public ObservableCollection<LockResult> LockResults
- {
- get { return _LockResults; }
- set { SetProperty(ref _LockResults, value); }
- }
- private bool _IsAllowEdit = false;
- public bool IsAllowEdit
- {
- get { return _IsAllowEdit; }
- set { SetProperty(ref _IsAllowEdit, value); }
- }
- // 可选:记录传感器 Id -> 索引 的映射,便于外部(如 Management)按 Id 更新
- private readonly Dictionary<string, int> _sensorIdToIndex = new Dictionary<string, int>();
- #endregion
- #region 命令
- public DelegateCommand LoadedCommand { get; set; }
- private DelegateCommand<ProductModel> _LoadProductCommand;
- public DelegateCommand<ProductModel> LoadProductCommand =>
- _LoadProductCommand ?? (_LoadProductCommand = new DelegateCommand<ProductModel>(ExecuteLoadProductCommand).ObservesCanExecute(() => CanLoad).ObservesProperty(() => SelectProduct).ObservesProperty(() => IsLoadProduct));
- private DelegateCommand _ResetCounterCommand;
- public DelegateCommand ResetCounterCommand =>
- _ResetCounterCommand ?? (_ResetCounterCommand = new DelegateCommand(ExecuteResetCounterCommand).ObservesCanExecute(() => DoCondition).ObservesProperty(() => isCanExecute));
- private bool DoCondition
- {
- get { return isCanExecute; }
- }
- private DelegateCommand<string> _CopyCommand;
- public DelegateCommand<string> CopyCommand =>
- _CopyCommand ?? (_CopyCommand = new DelegateCommand<string>(ExecuteCopyCommand));
- private DelegateCommand _TorqueInspectionCommand;
- public DelegateCommand TorqueInspectionCommand =>
- _TorqueInspectionCommand ?? (_TorqueInspectionCommand = new DelegateCommand(ExecuteTorqueInspectionCommand));
- //更换吸嘴
- private DelegateCommand _ChangeNozzleCommand;
- public DelegateCommand ChangeNozzleCommand =>
- _ChangeNozzleCommand ?? (_ChangeNozzleCommand = new DelegateCommand(ExecuteChangeNozzleCommand));
- //更换披头
- private DelegateCommand _ChangeHeaderCommand;
- public DelegateCommand ChangeHeaderCommand =>
- _ChangeHeaderCommand ?? (_ChangeHeaderCommand = new DelegateCommand(ExecuteChangeHeaderCommand));
- //添加螺丝
- private DelegateCommand _AddScrewCommand;
- public DelegateCommand AddScrewCommand =>
- _AddScrewCommand ?? (_AddScrewCommand = new DelegateCommand(ExecuteAddScrewCommand));
- private DelegateCommand _SetAlarmValueCommand;
- public DelegateCommand SetAlarmValueCommand =>
- _SetAlarmValueCommand ?? (_SetAlarmValueCommand = new DelegateCommand(ExecuteSetAlarmValueCommand));
- #endregion
- #region 事件
- #endregion
- public HomeViewModel(IEventAggregator ea, IContainerProvider container, IProductService productService, IConfigService configService, IRemoteCommandService remoteCommandService
- , ISystemDatabaseService systemDatabaseService, IDialogService dialogService)
- {
- _eventAggregator = ea;
- _container = container;
- _dialogService = dialogService;
- _productService = productService;
- LoadedCommand = new DelegateCommand(OnLoad);
- _eventAggregator.GetEvent<TaskMessageNotification>().Subscribe(AddMessageInvoke);
- //订阅权限登录事件
- _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
- management = _container.Resolve<Management>();
- _configService = configService;
- _productService.OnProductChanged += _productService_OnProductChanged;
- _remoteCommandService = remoteCommandService;
- _remoteCommandService.CycleTimingTicked += _remoteCommandService_CycleTimingTicked;
- _systemDatabaseService = systemDatabaseService;
- _eventAggregator.GetEvent<LockFinishNotification>().Subscribe(OnLockFinish);
- _eventAggregator.GetEvent<PressureFinishNotification>().Subscribe(OnPressureFinish);
- InitPressurePlots();
- }
- private void _remoteCommandService_CycleTimingTicked(object sender, TimeSpan e)
- {
- try
- {
- if (App.Current != null)
- {
- App.Current.Invoke(() =>
- {
- CTTotalSeconds = e.TotalSeconds;
- });
- }
- }
- catch (Exception)
- {
- }
- }
- #region 方法
- bool isFirst = true;
- private void OnLoad()
- {
- if (!isFirst)
- {
- return;
- }
- InitLockCurvePlotModel();
- isFirst = false;
- if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- async void ExecuteLoadProductCommand(ProductModel product)
- {
- if (product == null) return;
- var view = new ShowMessage(Lang.是否加载产品, $"{Lang.加载产品}:{product.Name}?");
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- IsLoadProduct = false;
- var waiting = new WaitingControl();
- //show the dialog
- var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
- await _productService.LoadProductAsync(product.ID);
- _productService.SetCurrentProduct(product.ID);
- await management.WriteParameterToPlcExAsync();
- if (DialogHost.IsDialogOpen("RootDialog"))
- {
- DialogHost.Close("RootDialog");
- }
- await task;
- //DatabaseHelper.AddLoadProductRecord(product.ID, product.Name, false);
- IsLoadProduct = true;
- }
- }
- }
- void ExecuteCopyCommand(string textToCopy)
- {
- Clipboard.SetText(textToCopy);
- }
- /// <summary>
- /// 添加消息至消息队列
- /// </summary>
- /// <param name="msg"></param>
- /// <param name="color"></param>
- public void AddMessage(string msg, Color color)
- {
- App.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- try
- {
- MessageQueue.Add(new TaskMessage()
- {
- DT = DateTime.Now,
- Message = msg,
- FontColol = new SolidColorBrush(color)
- });
- LogHelper.WriteLogInfo(msg);
- }
- catch (Exception)
- {
- }
- }));
- }
- /// <summary>
- /// 添加消息至消息队列
- /// </summary>
- /// <param name="msg"></param>
- /// <param name="color"></param>
- public void AddMessage(string msg, MessageLevel level)
- {
- MessageStruct messageStruct = new MessageStruct() { Message = msg, level = level };
- App.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- AddMessage(messageStruct);
- }));
- }
- /// <summary>
- /// 添加消息至消息队列
- /// </summary>
- /// <param name="messageStruct"></param>
- public void AddMessage(MessageStruct messageStruct)
- {
- try
- {
- if (MessageQueue.Count >= 100)
- {
- MessageQueue.RemoveAt(0);// 从队列头部移除最早的消息
- }
- Color color = Colors.Black;
- switch (messageStruct.level)
- {
- case MessageLevel.Info:
- color = Colors.Black;
- break;
- case MessageLevel.Debug:
- color = Colors.Green;
- break;
- case MessageLevel.Alarm:
- color = Colors.Orange;
- break;
- case MessageLevel.Error:
- color = Colors.Red;
- break;
- }
- MessageQueue.Add(new TaskMessage()
- {
- DT = DateTime.Now,
- Message = messageStruct.Message,
- FontColol = new SolidColorBrush(color)
- });
- LogHelper.WriteLogInfo(messageStruct.Message);
- }
- catch (Exception)
- {
- }
- }
- public void AddMessageInvoke(MessageStruct messageStruct)
- {
- App.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- AddMessage(messageStruct);
- }));
- }
- private void LoginChange(Models.User user)
- {
- if (user.userPart == Enums.UserPart.Operator)
- {
- IsAllowEdit = false;
- }
- else
- {
- IsAllowEdit = true;
- }
- }
- /// <summary>
- /// 重置计数
- /// </summary>
- async void ExecuteResetCounterCommand()
- {
- var currentProduct = _productService.GetCurrentProduct();
- if (currentProduct == null) return;
- var view = new ShowMessage(Lang.计数清零, Lang.是否重置当前产品的计数);
- //show the dialog
- var result = await DialogHost.Show(view, "RootDialog", null, null, null);
- if (result != null && result is bool)
- {
- if (((bool)result))
- {
- isCanExecute = false;
- await _systemDatabaseService.ResetProductionAsync(currentProduct.Name);
- await _systemDatabaseService.ResetThrowNumberAsync();
- isCanExecute = true;
- }
- }
- }
- /// <summary>
- /// 初始化曲线图
- /// </summary>
- private void InitLockCurvePlotModel()
- {
- var model = new PlotModel
- {
- Title = Lang.锁付曲线,
- TitleFontSize = 16
- };
- // 图例
- var legend = new Legend
- {
- LegendPosition = LegendPosition.TopRight,
- LegendPlacement = LegendPlacement.Outside,
- LegendOrientation = LegendOrientation.Vertical,
- LegendBorderThickness = 0
- };
- model.Legends.Add(legend);
- // X轴(圈数)
- var xAxis = new LinearAxis
- {
- Key = "X",
- Position = AxisPosition.Bottom,
- Title = Lang.锁付圈数,
- Minimum = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MinorGridlineStyle = LineStyle.Dot
- };
- model.Axes.Add(xAxis);
- // Y轴(力矩)
- var yAxis = new LinearAxis
- {
- Key = "Y",
- Position = AxisPosition.Left,
- Title = Lang.力矩kgf,
- MajorGridlineStyle = LineStyle.Solid,
- MinorGridlineStyle = LineStyle.Dot
- };
- model.Axes.Add(yAxis);
- // 实际锁付曲线
- var torqueSeries = new LineSeries
- {
- Title = Lang.锁付力矩曲线,
- StrokeThickness = 2,
- MarkerSize = 3,
- MarkerType = MarkerType.Circle,
- CanTrackerInterpolatePoints = false,
- Color = OxyColors.Blue
- };
- model.Series.Add(torqueSeries);
- // 上限线
- var upperLimitSeries = new LineSeries
- {
- Title = "Torque Upper Limit",
- StrokeThickness = 2,
- LineStyle = LineStyle.Dash,
- Color = OxyColors.Red
- };
- model.Series.Add(upperLimitSeries);
- // 下限线
- var lowerLimitSeries = new LineSeries
- {
- Title = "Torque Lower Limit",
- StrokeThickness = 2,
- LineStyle = LineStyle.Dash,
- Color = OxyColors.Green
- };
- model.Series.Add(lowerLimitSeries);
- LockCurvePlotModel = model;
- }
- /// <summary>
- /// 螺丝锁付完成时调用
- /// </summary>
- /// <param name="result"></param>
- private void OnLockFinish(LockResult result)
- {
- //如果当前螺丝编号为1,则清除之前的结果
- if (result.Number == 1)
- {
- LockResults.Clear();
- }
- LockResults.Add(result);
- App.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- try
- {
- //获取三条曲线
- var torqueSeries = LockCurvePlotModel.Series[0] as LineSeries; //实际扭矩
- var upperSeries = LockCurvePlotModel.Series[1] as LineSeries; //上限
- var lowerSeries = LockCurvePlotModel.Series[2] as LineSeries; //下限
- torqueSeries.Points.Clear();
- upperSeries.Points.Clear();
- lowerSeries.Points.Clear();
- //上下限值(根据你的工艺设置)
- double upperLimit = result.TargetTorqueUpperLimit; //上限扭矩
- double lowerLimit = result.TargetTorqueLowerLimit; //下限扭矩
- foreach (var waveData in result.WaveDatas)
- {
- //实际曲线
- torqueSeries.Points.Add(new OxyPlot.DataPoint(waveData.Turns, waveData.Torque));
- //上限曲线(固定扭矩)
- upperSeries.Points.Add(new OxyPlot.DataPoint(waveData.Turns, upperLimit));
- //下限曲线
- lowerSeries.Points.Add(new OxyPlot.DataPoint(waveData.Turns, lowerLimit));
- }
- //刷新
- LockCurvePlotModel.ResetAllAxes();
- LockCurvePlotModel.InvalidatePlot(true);
- //保存图片
- if (!string.IsNullOrEmpty(result.LockCurveImagePath))
- {
- PngExporter.Export(
- LockCurvePlotModel,
- result.LockCurveImagePath,
- (int)LockCurvePlotModel.Width,
- (int)LockCurvePlotModel.Height);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError("更新曲线图和保存曲线图时出错!", ex);
- }
- }));
- }
- /// <summary>
- /// 添加螺丝
- /// </summary>
- private void ExecuteAddScrewCommand()
- {
- _dialogService.ShowDialog("AddScrew", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- /// <summary>
- /// 更换披头
- /// </summary>
- void ExecuteChangeHeaderCommand()
- {
- _dialogService.ShowDialog("ChangeHeader", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- /// <summary>
- /// 更换吸嘴
- /// </summary>
- void ExecuteChangeNozzleCommand()
- {
- _dialogService.ShowDialog("ChangeNozzle", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- void ExecuteTorqueInspectionCommand()
- {
- _dialogService.ShowDialog("TorqueCheck", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- void ExecuteSetAlarmValueCommand()
- {
- _dialogService.ShowDialog("SetAlarmValue", rst =>
- {
- //对话框关闭之后的回调函数,可以在这解析结果。
- ButtonResult result1 = rst.Result;
- if (result1 == ButtonResult.OK)
- {
- _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = Lang.完成, Duration = 1 });
- }
- });
- }
- /// <summary>
- /// 保压完成时调用
- /// </summary>
- /// <param name="tuple"></param>
- private void OnPressureFinish((bool IsSuccess, (DateTime Timestamp, float Value)[] values, string SavePath) tuple)
- {
- //更新对应传感器的曲线图
- //App.Current.Dispatcher.BeginInvoke(new Action(() =>
- //{
- // var model = PressurePlotModel;
- // var series = model.Series[0] as LineSeries;
- // series.Points.Clear();
- // //第一个点的时间作为X轴起点
- // DateTime xAxisStart = tuple.values[0].Timestamp;
- // foreach (var dataPoint in tuple.values)
- // {
- // // 计算相对于起点的秒数作为X轴坐标
- // double xValue = (dataPoint.Timestamp - xAxisStart).TotalSeconds;
- // series.Points.Add(new OxyPlot.DataPoint(xValue, dataPoint.Value));
- // }
- // // 重置所有轴的范围以适应新数据
- // model.ResetAllAxes();
- // model.InvalidatePlot(true);
- // if (!string.IsNullOrEmpty(tuple.SavePath))
- // {
- // if (!Directory.Exists(Path.GetDirectoryName(tuple.SavePath)))
- // {
- // Directory.CreateDirectory(Path.GetDirectoryName(tuple.SavePath));
- // }
- // PngExporter.Export(model, tuple.SavePath, (int)model.Width, (int)model.Height);
- // }
- //}));
- }
- // 初始化由配置决定的曲线数量(在读取 SystemConfiguration 后调用)
- public void InitPressurePlots()
- {
- var model = CreatePlotModelForSensor();
- PressurePlotModel = model;
- }
- private PlotModel CreatePlotModelForSensor()
- {
- var model = new PlotModel { Title = $"压力曲线", TitleFontSize = 16 };
- // 设置图例
- var legend = new Legend
- {
- LegendPosition = LegendPosition.TopRight,
- LegendPlacement = LegendPlacement.Outside,
- LegendOrientation = LegendOrientation.Vertical,
- LegendBorderThickness = 0
- };
- model.Legends.Add(legend);
- // 设置X轴
- var xAxis = new LinearAxis
- {
- Key = "X",
- Position = AxisPosition.Bottom,
- Title = "Time (s)",
- Minimum = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MinorGridlineStyle = LineStyle.Dot
- };
- model.Axes.Add(xAxis);
- // 设置Y轴
- var yAxis = new LinearAxis
- {
- Key = "Y",
- Position = AxisPosition.Left,
- Title = "Pressure",
- MajorGridlineStyle = LineStyle.Solid,
- MinorGridlineStyle = LineStyle.Dot
- };
- model.Axes.Add(yAxis);
- // 添加示例数据系列
- var series = new LineSeries
- {
- Title = $"Sensor 1",
- StrokeThickness = 2,
- MarkerSize = 3,
- MarkerType = MarkerType.Circle,
- CanTrackerInterpolatePoints = false,
- };
- model.Series.Add(series);
- return model;
- }
- #endregion
- #region 继承
- /// <summary>
- /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <param name="continuationCallback"></param>
- public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
- {
- continuationCallback(true);
- }
- /// <summary>
- /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <exception cref="NotImplementedException"></exception>
- public async void OnNavigatedTo(NavigationContext navigationContext)
- {
- try
- {
- ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogError(Lang.主界面界面进入时出错, ex);
- }
- }
- /// <summary>
- /// 是否允许导航到此视图模型。
- /// </summary>
- /// <param name="navigationContext"></param>
- /// <returns></returns>
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- /// <summary>
- /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
- /// </summary>
- /// <param name="navigationContext"></param>
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- #endregion
- private void _productService_OnProductChanged(ProductModel obj)
- {
- App.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- CurrentProduct = obj;
- }));
- }
- }
- }
|