public MainWindowViewModel() { _client = new HttpClient(); _baseURL = "https://localhost:44351/api/MasterMind"; _gameId = -1; Attempts = new ObservableCollection <Attempt>(); GetValidCharacters(); CreateGameCommand = new GeneralNoParameterCommand(CreateGame); AttemptGameCommand = new GeneralNoParameterCommand(() => { ValueOne = string.IsNullOrWhiteSpace(ValueOne) ? "A" : ValueOne.ToUpper(); ValueTwo = string.IsNullOrWhiteSpace(ValueTwo) ? "A" : ValueTwo.ToUpper(); ValueThree = string.IsNullOrWhiteSpace(ValueThree) ? "A" : ValueThree.ToUpper(); ValueFour = string.IsNullOrWhiteSpace(ValueFour) ? "A" : ValueFour.ToUpper(); OnPropertyChanged("ValueOne"); OnPropertyChanged("ValueTwo"); OnPropertyChanged("ValueThree"); OnPropertyChanged("ValueFour"); string completeAttempt = $"{_gameId}_{ValueOne}{ValueTwo}{ValueThree}{ValueFour}"; AttemptGame(completeAttempt); }); }
// Evaluate the comparison values and set the target value accordingly private void compareValues() { if (AssociatedObject == null || _targetProperty == null) { return; } // Re-establish the binding between TargetValue and the target property. Throttle the call to avoid // errors resulting from multiple calls stepping on one another. if (_setBindingThrottler == null) { _setBindingThrottler = new ThrottleTimer(10) { Action = () => { setValueBinding(TargetProperty); } } } ; _setBindingThrottler.Invoke(); if (ValueTwo == ValueOne || (ValueTwo != null && ValueTwo.Equals(ValueOne))) { // Comparison values are equivalent // Hold on to the current value so it can be restored later _lastTargetValue = AssociatedObject.GetValue(_targetProperty); // Apply the target value TargetValue = ToggleValue; } else { // Comparison values are not equivalent. Apply the previous value. TargetValue = _lastTargetValue; } } #endregion }