コード例 #1
0
        /// <summary>
        /// Determines whether the given set of values defines a valid range or not.
        /// A valid range adheres to this constrain: MinValue <= Value <= MaxValue.
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        bool IsValidRange(ByteUpDown range)
        {
            if (range.MinValue <= range.Value && range.Value <= range.MaxValue)
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public List <WDetailSingleRowViewModel> CustomizeHeader(PropertyInfo property, string display_name, bool is_editable, object source)
        {
            WDetailSingleRowViewModel byte_row = new WDetailSingleRowViewModel(display_name);

            ByteUpDown byteupdown = new ByteUpDown();

            byteupdown.IsEnabled = is_editable;

            Binding tbind = new Binding(property.Name)
            {
                Source = source,
                Mode   = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            };

            byteupdown.SetBinding(ByteUpDown.ValueProperty, tbind);

            byte_row.PropertyControl = byteupdown;

            return(new List <WDetailSingleRowViewModel>()
            {
                byte_row
            });
        }
コード例 #3
0
        /// <summary>
        /// Tests all permutions for all sequences of three elements.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="val"></param>
        /// <param name="max"></param>
        public void TestAllPermutations(byte min, byte val, byte max)
        {
            string[,] ctrl = new string[6, 3]
            {
                { "min", "val", "max" },
                { "val", "min", "max" },
                { "val", "max", "min" },
                { "val", "min", "max" },
                { "min", "max", "val" },
                { "max", "min", "val" },
            };

            for (int i = 0; i < 6; i++)
            {
                var    range           = new ByteUpDown();
                string testPermutation = "";

                for (int j = 0; j < 3; j++)
                {
                    var itemToSet = ctrl[i, j];

                    if (string.IsNullOrEmpty(testPermutation))
                    {
                        testPermutation = itemToSet;
                    }
                    else
                    {
                        testPermutation += ", " + itemToSet;
                    }

                    switch (itemToSet)
                    {
                    case "min":
                        range.MinValue = min;
                        Assert.IsTrue(IsValidRange(range));
                        break;

                    case "val":
                        range.Value = val;
                        Assert.IsTrue(IsValidRange(range));
                        break;

                    case "max":
                        range.MaxValue = max;
                        Assert.IsTrue(IsValidRange(range));
                        break;

                    default:
                        break;
                    }
                }

                Console.WriteLine("Testing Permutation {0}: {1} - min={2}, val={3}, max={4}", i, testPermutation, min, val, max);
                Assert.IsTrue(IsValidRange(range));

                Assert.IsTrue(range.MinValue == min);
                Assert.IsTrue(range.Value == val);
                Assert.IsTrue(range.MaxValue == max);

                // Test if increment command works as expected
                while (range.MaxValue > range.Value)
                {
                    Assert.IsTrue(InputBaseUpDown.IncreaseCommand.CanExecute(null, range));
                    InputBaseUpDown.IncreaseCommand.Execute(null, range);
                }
                Assert.IsTrue(range.MaxValue == range.Value);

                // Test if decrement command works as expected
                while (range.MinValue < range.Value)
                {
                    Assert.IsTrue(InputBaseUpDown.DecreaseCommand.CanExecute(null, range));
                    InputBaseUpDown.DecreaseCommand.Execute(null, range);
                }
                Assert.IsTrue(range.MinValue == range.Value);
            }
        }