Ejemplo n.º 1
0
        public void SetValue_Should_Not_Cause_StackOverflow_And_Have_Correct_Values()
        {
            var viewModel = new TestStackOverflowViewModel()
            {
                Value = 50
            };

            var target = new Class1();

            target.Bind(Class1.DoubleValueProperty, new Binding("Value")
            {
                Mode   = BindingMode.TwoWay,
                Source = viewModel
            });

            var child = new Class1();

            child[!!Class1.DoubleValueProperty] = target[!!Class1.DoubleValueProperty];

            Assert.Equal(1, viewModel.SetterInvokedCount);

            // Issues #855 and #824 were causing a StackOverflowException at this point.
            target.DoubleValue = 51.001;

            Assert.Equal(2, viewModel.SetterInvokedCount);

            double expected = 51;

            Assert.Equal(expected, viewModel.Value);
            Assert.Equal(expected, target.DoubleValue);
            Assert.Equal(expected, child.DoubleValue);
        }
        public void SelectedItem_Should_Not_Cause_StackOverflow()
        {
            var viewModel = new TestStackOverflowViewModel()
            {
                Items = new List <string> {
                    "foo", "bar", "baz"
                }
            };

            var target = new ListBox
            {
                Template    = new FuncControlTemplate(CreateListBoxTemplate),
                DataContext = viewModel,
                Items       = viewModel.Items
            };

            target.Bind(ListBox.SelectedItemProperty,
                        new Binding("SelectedItem")
            {
                Mode = BindingMode.TwoWay
            });

            Assert.Equal(0, viewModel.SetterInvokedCount);

            // In Issue #855, a Stackoverflow occured here.
            target.SelectedItem = viewModel.Items[2];

            Assert.Equal(viewModel.Items[1], target.SelectedItem);
            Assert.Equal(1, viewModel.SetterInvokedCount);
        }
Ejemplo n.º 3
0
        public void SetValue_Should_Not_Cause_StackOverflow_And_Have_Correct_Values()
        {
            var viewModel = new TestStackOverflowViewModel()
            {
                Value = 50
            };

            var target = new DirectPropertyClass();

            target.Bind(DirectPropertyClass.DoubleValueProperty, new Binding("Value")
            {
                Mode   = BindingMode.TwoWay,
                Source = viewModel
            });

            var child = new DirectPropertyClass();

            child.Bind(DirectPropertyClass.DoubleValueProperty,
                       new Binding("DoubleValue")
            {
                Mode   = BindingMode.TwoWay,
                Source = target
            });

            Assert.Equal(1, viewModel.SetterInvokedCount);

            //here in real life stack overflow exception is thrown issue #855 and #824
            target.DoubleValue = 51.001;

            Assert.Equal(2, viewModel.SetterInvokedCount);

            double expected = 51;

            Assert.Equal(expected, viewModel.Value);
            Assert.Equal(expected, target.DoubleValue);
            Assert.Equal(expected, child.DoubleValue);
        }
Ejemplo n.º 4
0
        public void SetValue_Should_Not_Cause_StackOverflow(bool useXamlBinding)
        {
            var viewModel = new TestStackOverflowViewModel()
            {
                Value = 50
            };

            Track track = null;

            var target = new TestRange()
            {
                Template = new FuncControlTemplate <RangeBase>(c =>
                {
                    track = new Track()
                    {
                        Width       = 100,
                        Orientation = Orientation.Horizontal,
                        [~~Track.MinimumProperty] = c[~~RangeBase.MinimumProperty],
                        [~~Track.MaximumProperty] = c[~~RangeBase.MaximumProperty],

                        Name  = "PART_Track",
                        Thumb = new Thumb()
                    };

                    if (useXamlBinding)
                    {
                        track.Bind(Track.ValueProperty, new Binding("Value")
                        {
                            Mode     = BindingMode.TwoWay,
                            Source   = c,
                            Priority = BindingPriority.Style
                        });
                    }
                    else
                    {
                        track[~~Track.ValueProperty] = c[~~RangeBase.ValueProperty];
                    }

                    return(track);
                }),
                Minimum     = 0,
                Maximum     = 100,
                DataContext = viewModel
            };

            target.Bind(TestRange.ValueProperty, new Binding("Value")
            {
                Mode = BindingMode.TwoWay
            });

            target.ApplyTemplate();
            track.Measure(new Size(100, 0));
            track.Arrange(new Rect(0, 0, 100, 0));

            Assert.Equal(1, viewModel.SetterInvokedCount);

            // Issues #855 and #824 were causing a StackOverflowException at this point.
            target.Value = 51.001;

            Assert.Equal(2, viewModel.SetterInvokedCount);

            double expected = 51;

            Assert.Equal(expected, viewModel.Value);
            Assert.Equal(expected, target.Value);
            Assert.Equal(expected, track.Value);
        }