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);
        }
Exemplo n.º 2
0
        private new void NewWindowOnOpened(object?sender, EventArgs e)
        {
            Screens    screens = new Window().Screens;
            PixelRect  pr      = screens.Primary.Bounds;
            PixelPoint pp      = new PixelPoint(pr.BottomRight.X / 5, pr.BottomRight.Y / 5);

            Position = pp;

            GridMain   = this.FindControl <Grid>("GridMain");
            LBSolution = this.FindControl <ListBox>("LBSolution");

            ColumnDefinition column2 = GridMain.ColumnDefinitions[0];

            column2.MaxWidth = 600;
            column2.MinWidth = 200;

            InvalidChars = new char[] { '"', '/', '\\', '<', '>', '?', '*', '|', ':' };

            SolutionNameLength = 70;

            CollectionLBSolution = new List <string>();
            TBSolutionName       = new TextBox();

            LMessage = new Label();

            Border border = new Border();

            border.Background = Brushes.Red;
            border.Child      = LMessage;

            PopupMessage = new Popup();
            PopupMessage.IsLightDismissEnabled = true;
            PopupMessage.PlacementAnchor       = PopupAnchor.Bottom;
            PopupMessage.PlacementTarget       = TBSolutionName;
            PopupMessage.Child = border;

            GridMain.Children.Add(PopupMessage);

            CollectionLBSolution.Add("Empty solution");

            Binding bLBSolution = new Binding();

            bLBSolution.Source = CollectionLBSolution;

            LBSolution.Bind(ListBox.ItemsProperty, bLBSolution);
            LBSolution.SelectedIndex = 0;
        }
Exemplo n.º 3
0
        public void SelectedItem_Validation()
        {
            var target = new ListBox
            {
                Template           = ListBoxTemplate(),
                Items              = new[] { "Foo" },
                ItemTemplate       = new FuncDataTemplate <string>((_, __) => new Canvas()),
                SelectionMode      = SelectionMode.AlwaysSelected,
                VirtualizationMode = ItemVirtualizationMode.None
            };

            Prepare(target);

            var exception      = new System.InvalidCastException("failed validation");
            var textObservable = new BehaviorSubject <BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));

            target.Bind(ComboBox.SelectedItemProperty, textObservable);

            Assert.True(DataValidationErrors.GetHasErrors(target));
            Assert.True(DataValidationErrors.GetErrors(target).SequenceEqual(new[] { exception }));
        }
        public MainWindow()
        {
            InitializeComponent();

            var comboImgBinding   = ImgCombo.Bind(ComboBox.ItemsProperty, sourcePath);
            var carousBinding     = ImagesCar.Bind(Carousel.ItemsProperty, sourceImg);
            var comboClassBinding = NumCombo.Bind(ComboBox.ItemsProperty, sourceNum);
            var listBocBinding    = ImagesListBox.Bind(ListBox.ItemsProperty, sourceLB);

            sourceNum.OnNext(new List <int> {
                0, 1, 2, 3, 4, 5
            });

            ImgCombo.SelectionChanged += (s, e) =>
            {
                sourceImg.OnNext(new List <Avalonia.Controls.Image> {
                    Images[ImgCombo.SelectedIndex]
                });
            };

            NumCombo.SelectionChanged += (s, e) =>
            {
                UpdateResults();
            };

            ClassButton.Click += (s, e) =>
            {
                StopButton.IsEnabled = true;
                ProccText.IsVisible  = true;
                NumCombo.IsEnabled   = true;
                if (!isProcessing)
                {
                    BeginSession();
                }
            };
            StopButton.Click += (s, e) =>
            {
                if (myRec != null)
                {
                    myRec.Stop();
                }
                isProcessing         = false;
                StopButton.IsEnabled = false;
                ProccText.IsVisible  = false;
            };

            DBButton.Click += (s, e) =>
            {
                int count;
                using (var db = new ImagesContext())
                {
                    var imgs = db.Images.ToList();
                    foreach (var im in imgs)
                    {
                        db.Images.Remove(im);
                    }
                    db.SaveChanges();
                    count = db.Images.ToList().Count;
                }
                DBAmountText.Text = "Pictures in database amount: " + count;
            };

            this.FindControl <Button>("ChooseDir").Click += async(s, e) =>
            {
                var dialog = new OpenFolderDialog();
                var res    = await dialog.ShowAsync(GetWindow());

                if (res != null)
                {
                    imgDir = res.ToString();
                    UpdateImages(imgDir);
                    ClassButton.IsEnabled = true;
                }
            };
        }