Example #1
0
 public AppData()
 {
     var source = new ConversionItemViewModel(UnitFactory.UnitFromName(Settings.LastUnitSource, Settings.LastCategory));
     source.Value = Settings.LastUnitSourceValue;
     var destination = new ConversionItemViewModel(UnitFactory.UnitFromName(Settings.LastUnitDestination, Settings.LastCategory));
     CurrentConversion = new SimpleConvertViewModel(Settings.LastCategory,source, destination);
 }
        public SimpleConvertViewModel(UnitCategory category, ConversionItemViewModel sourceUnit, ConversionItemViewModel destinationUnit)
        {
            _currentCategory = category;

            // get default source if it doesn't exist
            if ((sourceUnit == null) || (destinationUnit == null))
            {
                SetDefaultUnits(category);
            }
            else
            {
                if ((sourceUnit.ConversionUnit == null || destinationUnit.ConversionUnit == null))
                    SetDefaultUnits(category);
                else
                {

                    this.SourceUnit = sourceUnit;
                    this.DestinationUnit = destinationUnit;
                    UserInputValue = sourceUnit.Value.ToString();
                }
               // TextInputValue = "0";
            }

            PopulateConversionList(_currentCategory);

            DigitPressedCommand = new Command<string>(ProcessDigit);
            ClearCommand = new Command(ProcessClear);
            EditAvailableItemsCommand = new Command(EditAvailableItems);
            CollapseKeyboardCommand = new Command(CollapseKeyboard);
            BackspaceCommand = new Command(ProcessBackspace);
            InformationCommand = new Command(ShowInformation);
            NegateCommand = new Command(NegateEntry);
            SwapValuesCommand = new Command(SwapValues);
            ChangeSourceUnitCommand = new Command(ChangeSourceUnit);
            ChangeDestinationUnitCommand = new Command(ChangeDestinationUnit);
            //            IncrementDecimalPlacesCommand = new Command(IncrementDecimalPlaces);
            //            DecrementDecimalPlacesCommand = new Command(DecrementDecimalPlaces);
            IsKeyaboardVisible = true;
        }
        private void UpdateSelectedUnit()
        {
            if (availableUnitList.SelectedItem == null)
                return;

            ConversionItemSelectionViewModel item = availableUnitList.SelectedItem as ConversionItemSelectionViewModel;

            AppData data = ((App)Application.Current).AppData;
            ConversionItemViewModel newItem = new ConversionItemViewModel(item.ConversionUnit);

            if (_isDestination)
            {
                data.CurrentConversion.DestinationUnit = newItem;
                newItem.ApplyConversion(data.CurrentConversion.SourceUnit);
            }
            else
            {
                var value = data.CurrentConversion.SourceUnit.Value;
                data.CurrentConversion.SourceUnit = newItem;
                data.CurrentConversion.SourceUnit.Value = value;
                data.CurrentConversion.DestinationUnit.ApplyConversion(data.CurrentConversion.SourceUnit);
            }
        }
 public void ApplyConversion(ConversionItemViewModel fromUnit)
 {
     // convert to unit
     var convResult = ConversionEngine.ConvertUnit(fromUnit.ConversionUnit, this.ConversionUnit, fromUnit.Value);
     this.Value = convResult;
 }