using Prism.Commands; using Prism.Ioc; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Media; using Team.FFFeederService; using Team.FFFeederService.Interfaces; using TeamAAS_VP.Controls; using TeamAAS_VP.Core; using TeamAAS_VP.Interfaces; namespace TeamAAS_VP.ViewModels.DebugMod { public class VisionSolutionViewModel : BindableBase, IConfirmNavigationRequest { IContainerProvider _container; ISystemDatabaseService _systemDatabaseService; private ImageSource _CurrentImage; public ImageSource CurrentImage { get { return _CurrentImage; } set { SetProperty(ref _CurrentImage, value); } } private FocusAnalyzerViewModel _FocusAnalyzerViewModel; public FocusAnalyzerViewModel FocusAnalyzerViewModel { get { return _FocusAnalyzerViewModel; } set { SetProperty(ref _FocusAnalyzerViewModel, value); } } //选择图片 private DelegateCommand _SelectImageCommand; public DelegateCommand SelectImageCommand => _SelectImageCommand ?? (_SelectImageCommand = new DelegateCommand(ExecuteSelectImageCommand)); private DelegateCommand _LoadedCommand; public DelegateCommand LoadedCommand => _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand)); public VisionSolutionViewModel(IContainerProvider container, ISystemDatabaseService systemDatabaseService) { _container = container; _systemDatabaseService = systemDatabaseService; } void ExecuteLoadedCommand() { try { if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator) { IsAllowEdit = false; } else { IsAllowEdit = true; } } catch (Exception) { } } /// /// 选择一张图像 /// void ExecuteSelectImageCommand() { //打开文件对话框,选择一张图片 Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Filter = "Image files (*.png;*.jpg;*.jpeg;*.bmp)|*.png;*.jpg;*.jpeg;*.bmp|All files (*.*)|*.*"; openFileDialog.Multiselect = true; bool? result = openFileDialog.ShowDialog(); if (result.HasValue) { if (openFileDialog.FileNames.Length > 0) { //加载第一张图片 string filePath = openFileDialog.FileNames[0]; try { System.Windows.Media.Imaging.BitmapImage bitmap = new System.Windows.Media.Imaging.BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(filePath, UriKind.Absolute); bitmap.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad; bitmap.EndInit(); FocusAnalyzerViewModel.CurrentImage = bitmap; } catch (Exception ex) { //显示错误信息 System.Windows.MessageBox.Show("加载图片失败:" + ex.Message); } } } } #region 继承 /// /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。 /// /// /// public void ConfirmNavigationRequest(NavigationContext navigationContext, Action continuationCallback) { continuationCallback(true); } /// /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。 /// /// /// public async void OnNavigatedTo(NavigationContext navigationContext) { if (FocusAnalyzerViewModel==null) { FocusAnalyzerViewModel = new FocusAnalyzerViewModel(); } } /// /// 是否允许导航到此视图模型。 /// /// /// public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } /// /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。 /// /// public void OnNavigatedFrom(NavigationContext navigationContext) { } #endregion private bool _IsAllowEdit = false; public bool IsAllowEdit { get { return _IsAllowEdit; } set { SetProperty(ref _IsAllowEdit, value); } } private void LoginChange(Models.User user) { if (user.userPart == Enums.UserPart.Operator) { IsAllowEdit = false; } else { IsAllowEdit = true; } } } }