Пример #1
0
        public static void AdjustItemWeights(Ingredient sender, double newWeight, ObservableCollection <Ingredient> items)
        {
            double oldWeight         = sender.GetExactWeight();
            double weightAdjustRatio = newWeight / oldWeight;


            for (int i = 0; i < items.Count; i++)
            {
                if (items[i] == sender)
                {
                    continue;
                }
                Ingredient ingredient    = items[i];
                double     updatedWeight = ingredient.GetExactWeight() * weightAdjustRatio;
                ingredient.AdjustWeight(updatedWeight);
            }
            sender.AdjustWeight(newWeight);
        }
Пример #2
0
        public static void AdjustItemWeights(object senderObj, double newWeight, List <Ingredient> items)
        {
            Ingredient sender            = senderObj as Ingredient;
            double     oldWeight         = sender.GetExactWeight();
            double     weightAdjustRatio = newWeight / oldWeight;


            for (int i = 0; i < items.Count; i++)
            {
                Ingredient ingredient = items[i];
                if (ingredient == sender)
                {
                    continue;
                }
                //if (i == items.Count - 1)
                //{
                //    ingredient.Weight = weightRemaining;
                //    break;
                //}
                double updatedWeight = ingredient.GetExactWeight() * weightAdjustRatio;

                ingredient.AdjustWeight(updatedWeight);
            }
        }