private void EntrySelector_ComboBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter && OKCommand.CanExecute(null)) { OKCommand.Execute(null); } }
private void Timer_Tick(object sender, EventArgs e) { if (timer.Tag == null) { timer.Tag = TimeSpan.FromSeconds(1); } else { timer.Tag = ((TimeSpan)timer.Tag).Add(TimeSpan.FromSeconds(1)); } if (((TimeSpan)timer.Tag) >= Expiry) { DisposeTimer(); InternalText = null; if (OKCommand != null) { if (OKCommand.CanExecute(null)) { OKCommand.Execute(null); } } else { Visibility = Visibility.Collapsed; } } if (!Text.IsNullOrEmpty() && Expiry.HasValue && timer?.Tag != null) { InternalText = Text.Replace("{TimeRemaining}", (Expiry.Value - (((TimeSpan?)timer.Tag) ?? TimeSpan.Zero)).ToReadableString()); } }
public RunExecutableViewModel(Window dialog, IFileDialogService fileDialogService) : base(dialog) { _fileDialogService = fileDialogService; CanExecuteOKCommand = () => !string.IsNullOrWhiteSpace(ExecutablePath); OKCommand.ObservesProperty(() => ExecutablePath); }
public TestFormViewModel() { OKCommand.Subscribe(item => { item.Result = true; if (Position.Value == ItemsSource.Count - 1) { TestFinished(); return; } Position.Value++; }); NGCommand.Subscribe(item => { item.Result = false; }); Position.Subscribe(pos => { if (ItemsSource == null) { return; } _prevItem?.CancelAction?.Invoke(); ItemsSource[pos].Action?.Invoke(); _prevItem = ItemsSource[pos]; }); }
public NewItemDialogViewModel(IProjectFolder folder) : base("New Item") { var shell = IoC.Get <IShell>(); templates = new ObservableCollection <ICodeTemplate>(); var compatibleTemplates = shell.CodeTemplates.Where(t => t.IsCompatible(folder.Project)); foreach (var template in compatibleTemplates) { templates.Add(template); } SelectedTemplate = templates.FirstOrDefault(); this.folder = folder; OKCommand = ReactiveCommand.Create(); OKCommand.Subscribe(_ => { SelectedTemplate?.Generate(folder); Close(); }); }
private void Window_Error(object sender, ValidationErrorEventArgs e) { var src = (DependencyObject)e.OriginalSource; switch (e.Action) { case ValidationErrorEventAction.Added: if (errorControls.Add(src)) { OKCommand.OnCanExecuteChanged(); ApplyCommand.OnCanExecuteChanged(); if (e.OriginalSource is FrameworkElement) { ((FrameworkElement)e.OriginalSource).Unloaded += Control_Unloaded; } } break; case ValidationErrorEventAction.Removed: if (!Validation.GetHasError((DependencyObject)e.OriginalSource)) { if (errorControls.Remove(src)) { OKCommand.OnCanExecuteChanged(); ApplyCommand.OnCanExecuteChanged(); if (e.OriginalSource is FrameworkElement) { ((FrameworkElement)e.OriginalSource).Unloaded -= Control_Unloaded; } } } break; } }
private void CanExecuteChanged(object sender, EventArgs e) { if (OKCommand != null) { _canExecute = OKCommand.CanExecute(null); } CoerceValue(UIElement.IsEnabledProperty); }
/// <summary> /// 显示 /// </summary> internal void Show() { IsShow = true; if (IsScan && null != cardNo) { OKCommand.Execute(null); } }
public STM32ProjectSetupModalDialogViewModel() : base("New STM32 Project", true, true) { OKCommand = ReactiveCommand.Create(); OKCommand.Subscribe((o) => { Close(); }); }
/// <summary> /// Handler for the PropertyChanged event /// </summary> /// <param name="sender">The source of the event</param> /// <param name="e">The event arguments associated with the event</param> void SelectReportModelDialogViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { //Hand switch (e.PropertyName) { case "SelectedDataModel": OKCommand.UpdateCanExecuteCommand(); break; } }
private void Control_Unloaded(object sender, RoutedEventArgs e) { if (sender is FrameworkElement) { ((FrameworkElement)sender).Unloaded -= Control_Unloaded; } errorControls.Remove((DependencyObject)sender); OKCommand.OnCanExecuteChanged(); ApplyCommand.OnCanExecuteChanged(); }
public VerificationCodePageViewModel(INavigationService navigationService) : base(navigationService) { Title = "Verification Code"; OKCommand = VerificationCode.Select(s => !string.IsNullOrEmpty(s)).ToReactiveCommand(); OKCommand.Subscribe(() => navigationService.GoBackAsync(VerificationCode.Value)); CancelCommand = new ReactiveCommand(); CancelCommand.Subscribe(() => navigationService.GoBackAsync()); }
void SelectReportGroupViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { switch (e.PropertyName) { case "SelectedReportGroup": case "ReportName": OKCommand.UpdateCanExecuteCommand(); break; } }
public NewProjectDialogViewModel() : base("New Project", true, true) { shell = IoC.Get <IShell>(); projectTemplates = new ObservableCollection <IProjectTemplate>(); Languages = new List <ILanguageService>(shell.LanguageServices); location = Platform.ProjectDirectory; SelectedLanguage = Languages.FirstOrDefault(); SelectedTemplate = ProjectTemplates.FirstOrDefault(); BrowseLocationCommand = ReactiveCommand.Create(); BrowseLocationCommand.Subscribe(async o => { var ofd = new OpenFolderDialog(); ofd.InitialDirectory = location; var result = await ofd.ShowAsync(); if (result != string.Empty) { Location = result; } }); OKCommand = ReactiveCommand.Create(this.WhenAny(x => x.Location, x => x.SolutionName, (location, solution) => !Directory.Exists(Path.Combine(location.Value, solution.Value)))); OKCommand.Subscribe(async o => { bool generateSolutionDirs = false; if (solution == null) { generateSolutionDirs = true; var destination = Path.Combine(location, solutionName); solution = Solution.Create(destination, solutionName, false); } if (await selectedTemplate.Generate(solution, name) != null) { if (generateSolutionDirs) { if (!Directory.Exists(solution.CurrentDirectory)) { Directory.CreateDirectory(solution.CurrentDirectory); } } } solution.Save(); shell.CurrentSolution = solution; solution = null; Close(); }); }
/// <summary> /// 显示 /// </summary> internal void Show() { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.LockOn)); IsDisplay = true; IsShow = true; if (IsScan && null != cardNo) { OKCommand.Execute(null); } }
public ProjectConfigurationDialogViewModel(IProject project, Action onClose) : base("Project Configuration", true, false) { ConfigPages = new List <object>(); ConfigPages.AddRange(project.ConfigurationPages); OKCommand = ReactiveCommand.Create(); OKCommand.Subscribe(o => { onClose(); Close(); }); }
public PickoutCoverViewModel() { PropertyChanged += PickOutCoverDialogViewModel_PropertyChanged; OKCommand.Subscribe(_ => { ExtractCover(); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); }) .AddTo(disposables); CancelCommand.Subscribe(_ => { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); }) .AddTo(disposables); }
public PackageManagerDialogViewModel() : base("Packages") { _packageManager = new PackageManager(this); AvailablePackages = new ObservableCollection <IPackageSearchMetadata>(); Dispatcher.UIThread.InvokeAsync(async() => { InvalidateInstalledPackages(); await DownloadCatalog(); }); InstallCommand = ReactiveCommand.Create(); InstallCommand.Subscribe(async _ => { await PackageManager.InstallPackage(selectedPackage.Identity.Id, selectedPackage.Identity.Version.ToFullString()); InvalidateInstalledPackages(); }); UninstallCommand = ReactiveCommand.Create(); UninstallCommand.Subscribe(async _ => { if (SelectedInstalledPackage != null) { await PackageManager.UninstallPackage(SelectedInstalledPackage.Model.Id, SelectedInstalledPackage.Model.Version.ToNormalizedString()); InvalidateInstalledPackages(); } }); OKCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.EnableInterface)); OKCommand.Subscribe(_ => { ShellViewModel.Instance.InvalidateCodeAnalysis(); Close(); }); EnableInterface = true; }
public PackageManagerDialogViewModel() : base("Packages") { AvailablePackages = new ObservableCollection <PackageReference>(); DownloadCatalog(); InstallCommand = ReactiveCommand.Create(); InstallCommand.Subscribe(async o => { EnableInterface = false; try { await SelectedPackageIndex.Synchronize(SelectedTag, this); //if (fullPackage.Install()) //{ // Status = "Package Installed Successfully."; //} //else //{ // Status = "An error occurred trying to install package."; //} } catch (Exception e) { Status = "An error occurred trying to install package. " + e.Message; } EnableInterface = true; }); OKCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.EnableInterface)); OKCommand.Subscribe(_ => { ShellViewModel.Instance.InvalidateCodeAnalysis(); Close(); }); EnableInterface = true; }
public AccountPanelViewModel(Config config) { Clients = config.Clients; var appRegistration = new ReactiveProperty<AppRegistration>(); var authClient = new ReactiveProperty<AuthenticationClient>(); Domain = new ReactiveProperty<string>(); var canExecuteAuthCommand = Domain.Select(x => !string.IsNullOrWhiteSpace(x)); AuthCommand = new ReactiveCommand(canExecuteAuthCommand); AuthCommand.Subscribe(async () => { authClient.Value = new AuthenticationClient(Domain.Value); appRegistration.Value = await authClient.Value.CreateApp("Mayodon Client", Scope.Read); System.Diagnostics.Process.Start(authClient.Value.OAuthUrl()); }); AuthCode = new ReactiveProperty<string>(); OKCommand = Observable.CombineLatest( appRegistration.Select(x => x != null), AuthCode.Select(x => !string.IsNullOrWhiteSpace(x)), (x, y) => x & y).ToReactiveCommand(); OKCommand.Subscribe(async () => { var auth = await authClient.Value.ConnectWithCode(AuthCode.Value); var client = new MastodonClient(appRegistration.Value, auth); var account = await client.GetCurrentUser(); config.Clients.Add(new Client() { App = appRegistration.Value, Auth = auth, Account = account }); config.Save(); Domain.Value = ""; AuthCode.Value = ""; }); }
public ExportDialogViewModel() { OKCommand.Subscribe(async _ => { await RunExport(); RequestClose.Invoke(new DialogResult(ButtonResult.OK)); }) .AddTo(_disposables); CancelCommand.Subscribe(_ => { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); }) .AddTo(_disposables); ReferenceCommand.Subscribe(_ => { ShowOpenFileDialog(); }) .AddTo(_disposables); TextVerifier.Value = new Func <string, bool?>((s) => Directory.Exists(s)); }
/// <summary> /// 处理KEY /// </summary> /// <param name="args"></param> internal void HandleKey(KeyEventArgs args) { // 如果是功能(如上下左右,换页) if (args.Key == Key.Right || args.Key == Key.Left) { if (args.Key == Key.Right && AlertMsgImageMode == 4 && SelectedMode == 1) { SelectedMode = 2; } else if (args.Key == Key.Left && AlertMsgImageMode == 4 && SelectedMode == 2) { SelectedMode = 1; } } // 如果要增加数量或减少数量 if (args.Key == Key.Escape || args.Key == Key.Enter) { if (AlertMsgButtonMode == 1) { OKCommand.Execute(null); } else if (AlertMsgButtonMode == 2) { if (args.Key == Key.Escape) { NoCommand.Execute(null); } else if (args.Key == Key.Enter) { if (SelectedMode == 1) { NoCommand.Execute(null); } else if (SelectedMode == 2) { YesCommand.Execute(null); } } } } }
public CustomDialogViewModel( IDialogService _dialogService, IRegionManager _regionManager ) { RegionManager = _regionManager; CustomDialogRegionManager.Value = RegionManager.CreateRegionManager(); OKCommand.Subscribe(Close).AddTo(DisposeCollection); RecursionCommand.Subscribe(() => { IDialogResult result = null; _dialogService.ShowDialog(nameof(CustomDialogView), new DialogParameters { { "Input", Input.Value } }, ret => result = ret); if (result != null) { Input.Value = result.Parameters.GetValue <string>("Input"); } }).AddTo(DisposeCollection); }
public CommandViewModel() { CanClose = new ReactiveProperty <bool>(false); AppDisplayName = new ReactiveProperty <string>(); Command = new ReactiveProperty <List <string> >(new List <string>()); IsAdmin = new ReactiveProperty <bool>(false); OKCommand = new[] { Command.Select(x => x.Where(y => !string.IsNullOrWhiteSpace(y)).Count() == 0), AppDisplayName.Select(x => string.IsNullOrWhiteSpace(x)) }.CombineLatestValuesAreAllFalse().ToReactiveCommand(); OKCommand.Subscribe(() => { UpdateAppInfo(); IsUpdate = true; CanClose.Value = true; }); CancelCommand = new ReactiveCommand(); CancelCommand.Subscribe(() => { IsUpdate = false; CanClose.Value = true; }); }
public SettingViewModel() { AppDisplayName = new ReactiveProperty <string>(); FilePath = new ReactiveProperty <string>(); Arguments = new ReactiveProperty <string>(); WorkDirectory = new ReactiveProperty <string>(); IsAdmin = new ReactiveProperty <bool>(); AppIcon = new ReactiveProperty <BitmapSource>(); CanClose = new ReactiveProperty <bool>(); OKCommand = new[] { AppDisplayName.Select(x => string.IsNullOrWhiteSpace(x)), FilePath.Select(x => string.IsNullOrWhiteSpace(x)) }.CombineLatestValuesAreAllFalse().ToReactiveCommand(); OKCommand.Subscribe(() => { if (HasChanges()) { if (!File.Exists(FilePath.Value) && !Directory.Exists(FilePath.Value)) { MessageBox.Show("ファイルが見つかりません。"); IsUpdate = true; CanClose.Value = false; return; } UpdateAppInfo(); IsUpdate = true; CanClose.Value = true; return; } //キャンセル扱い IsUpdate = false; CanClose.Value = true; }); CancelCommand = new ReactiveCommand(); CancelCommand.Subscribe(() => { IsUpdate = false; CanClose.Value = true;//キャンセルは常にtrue }); }
public AttachToProcessViewModel(Window dialog) : base(dialog) { CanExecuteOKCommand = () => SelectedProcess != null; OKCommand.ObservesProperty(() => SelectedProcess); }
public SelectProcessesViewModel(Window dialog, DriverInterface driver) : base(dialog) { _driver = driver; CanExecuteOKCommand = () => SelectedProcesses.Count > 0; OKCommand = OKCommand.ObservesProperty(() => SelectedItem); }
/// <summary> /// コンストラクタ /// </summary> public CameraCapturingViewModel() { OKCommand.Subscribe(OKInteraction); CancelCommand.Subscribe(CancelInteraction); }
public AboutDialogViewModel() : base("About", true, false) { OKCommand = ReactiveCommand.Create(); OKCommand.Subscribe(o => { Close(); }); }
public NewImageViewModel(Window window) : base(window) { CanExecuteOKCommand = () => !string.IsNullOrWhiteSpace(ImageName); OKCommand.ObservesProperty(() => ImageName); }