コード例 #1
0
        internal IngredientReferenceEditorViewModel(BindingList <ValueDisplayItem> ingredients, IngredientReferenceViewModel reference)
        {
            mIngredients = ingredients;
            mReference   = reference;

            IngredientID = reference.IngredientID;
            Amount       = reference.Amount.Value;
            Measurement  = reference.Amount.Measurement;

            mAddIngredientCommand = new DelegateCommand(DoAddIngredient);
            Commit();
        }
コード例 #2
0
        public ReduceRecipeItemViewModel(IngredientReferenceViewModel ingredient)
        {
            mIngredient   = ingredient;
            mMeasurements = new BindingList <ValueDisplayItem>();

            Postfix = string.Format("of {0}", ingredient.Name);

            var amount = ingredient.Amount;
            var attr   = sMeasurementAttributes[amount.Measurement];

            if (attr is OfCategoryAttribute)
            {
                Enabled       = false;
                mSelectedItem = new AmountItem(amount);
                mMeasurements.Add(mSelectedItem);
            }
            else
            {
                Enabled = true;

                var baseValue = amount.Value * attr.Factor;

                var type = attr.GetType();
                foreach (var kvp in sMeasurementAttributes)
                {
                    var measurement = kvp.Key;
                    if (kvp.Value.GetType() == type)
                    {
                        var item = new MeasurementFractionItem(baseValue, measurement, sMeasurementAttributes[measurement]);
                        mMeasurements.Add(item);
                        if (item.Measurement == amount.Measurement)
                        {
                            mSelectedItem = item;
                        }
                    }
                }
            }

            Commit();
        }