Ejemplo n.º 1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
        {
            string[]      s           = (parameter as string).Split(new char[] { '|' });
            UnitCultureId unitCulture = (UnitCultureId)value;

            if (unitCulture == UnitCultureId.Metric)
            {
                return(s[0]);
            }
            else
            {
                return(s[1]);
            }
        }
Ejemplo n.º 2
0
        public string GetFormattedValueOfType(UnitCultureId unitCultureId)
        {
            string formattedValue = String.Empty;

            // Special case for height
            if (this.MeasurementId == Model.MeasurementId.Height)
            {
                formattedValue = this.MeasurementType.GetAltDefaultUnit(unitCultureId).GetFormattedValue(this.Value);
            }
            // Special case for weight
            else if (this.MeasurementId == Model.MeasurementId.Weight)
            {
                // Inlcude both stones and lbs in Imperial measurement for weight
                if (unitCultureId == UnitCultureId.Imperial)
                {
                    string lb = this.MeasurementType.GetDefaultUnit(unitCultureId).GetFormattedValue(this.Value);
                    string st = this.MeasurementType.GetAltDefaultUnit(unitCultureId).GetFormattedValue(this.Value);
                    // Return empty string if both strings are empty since any string other than empty triggers the enabled state on the MeasurementBtn
                    if (lb != String.Empty &&
                        st != String.Empty)
                    {
                        formattedValue = String.Format("{0} ({1})", lb, st);
                    }
                    else
                    {
                        formattedValue = String.Empty;
                    }
                }
                else
                {
                    formattedValue = this.MeasurementType.GetDefaultUnit(unitCultureId).GetFormattedValue(this.Value);
                }
            }
            // All others
            else
            {
                formattedValue = this.MeasurementType.GetDefaultUnit(unitCultureId).GetFormattedValue(this.Value);
            }
            return(formattedValue);
        }
        public IUnit GetAltDefaultUnit(UnitCultureId unitCultureId)
        {
            UnitId id = this.AltDefaultUnitDict[unitCultureId];

            return((from IUnit u in this.Units where u.Id == id select u).First());
        }