예제 #1
0
        public void Inserting_Then_Removing_Should_Add_Remove_Containers()
        {
            var items  = new AvaloniaList <string>(Enumerable.Range(0, 5).Select(x => $"Item {x}"));
            var toAdd  = Enumerable.Range(0, 3).Select(x => $"Added Item {x}").ToArray();
            var target = new ItemsPresenter
            {
                VirtualizationMode = ItemVirtualizationMode.None,
                Items        = items,
                ItemTemplate = new FuncDataTemplate <string>(x => new TextBlock {
                    Height = 10
                }),
            };

            target.ApplyTemplate();

            Assert.Equal(items.Count, target.Panel.Children.Count);

            foreach (var item in toAdd)
            {
                items.Insert(1, item);
            }

            Assert.Equal(items.Count, target.Panel.Children.Count);

            foreach (var item in toAdd)
            {
                items.Remove(item);
            }

            Assert.Equal(items.Count, target.Panel.Children.Count);
        }
        public void CreateDerivedList_Handles_Remove()
        {
            var source = new AvaloniaList <int>(new[] { 0, 1, 2, 3 });
            var target = source.CreateDerivedList(x => new Wrapper(x));

            source.Remove(2);

            var result = target.Select(x => x.Value).ToList();

            Assert.Equal(source, result);
        }
예제 #3
0
        public void ListBox_Should_Be_Valid_After_Remove_Of_Item_In_NonVisibleArea()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var items = new AvaloniaList <string>(Enumerable.Range(1, 30).Select(v => v.ToString()));

                var wnd = new Window()
                {
                    Width = 100, Height = 100, IsVisible = true
                };

                var target = new ListBox()
                {
                    AutoScrollToSelectedItem = true,
                    Height             = 100,
                    Width              = 50,
                    VirtualizationMode = ItemVirtualizationMode.Simple,
                    ItemTemplate       = new FuncDataTemplate <object>((c, _) => new Border()
                    {
                        Height = 10
                    }),
                    Items = items,
                };
                wnd.Content = target;

                var lm = wnd.LayoutManager;

                lm.ExecuteInitialLayoutPass();

                //select last / scroll to last item
                target.SelectedItem = items.Last();

                lm.ExecuteLayoutPass();

                //remove the first item (in non realized area of the listbox)
                items.Remove("1");
                lm.ExecuteLayoutPass();

                Assert.Equal("30", target.ItemContainerGenerator.ContainerFromIndex(items.Count - 1).DataContext);
                Assert.Equal("29", target.ItemContainerGenerator.ContainerFromIndex(items.Count - 2).DataContext);
                Assert.Equal("28", target.ItemContainerGenerator.ContainerFromIndex(items.Count - 3).DataContext);
                Assert.Equal("27", target.ItemContainerGenerator.ContainerFromIndex(items.Count - 4).DataContext);
                Assert.Equal("26", target.ItemContainerGenerator.ContainerFromIndex(items.Count - 5).DataContext);
            }
        }
예제 #4
0
        public void Removing_Item_Should_Raise_CollectionChanged()
        {
            var target = new AvaloniaList <int>(new[] { 1, 2, 3 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.Equal(new[] { 3 }, e.OldItems.Cast <int>());
                Assert.Equal(2, e.OldStartingIndex);

                raised = true;
            };

            target.Remove(3);

            Assert.True(raised);
        }
예제 #5
0
        public void Removing_Items_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ItemsControl();
            var items  = new AvaloniaList <string> {
                "Foo", "Bar"
            };
            var called = false;

            target.Template = GetTemplate();
            target.Items    = items;
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged                   += (s, e) =>
                                                                             called = e.Action == NotifyCollectionChangedAction.Remove;

            items.Remove("Bar");

            Assert.True(called);
        }
예제 #6
0
        public async Task <Download?> DownloadAsync(Server server)
        {
            if (server.DownloadUrl == null)
            {
                throw new ArgumentNullException(nameof(server.DownloadUrl));
            }

            var download = new Download(server.DownloadUrl, server.InstallationPath);

            if (!download.CanStart())
            {
                return(null);
            }

            _downloads.Remove(_downloads.FirstOrDefault(d => d.ForkAndVersion == download.ForkAndVersion));

            _downloads.Add(download);
            await download.StartAsync(_http);

            return(download);
        }
예제 #7
0
        public void Containers_Correct_After_Clear_Add_Remove()
        {
            // Issue #1936
            var items  = new AvaloniaList <string>(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
            var target = new ListBox
            {
                Template     = ListBoxTemplate(),
                Items        = items,
                ItemTemplate = new FuncDataTemplate <string>((x, _) => new TextBlock {
                    Width = 20, Height = 10
                }),
                SelectedIndex = 0,
            };

            Prepare(target);

            items.Clear();
            items.AddRange(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
            items.Remove("Item 2");

            Assert.Equal(
                items,
                target.Presenter.Panel.Children.Cast <ListBoxItem>().Select(x => (string)x.Content));
        }
예제 #8
0
        public void Inserting_Then_Removing_Should_Add_Remove_Containers()
        {
            var items = new AvaloniaList<string>(Enumerable.Range(0, 5).Select(x => $"Item {x}"));
            var toAdd = Enumerable.Range(0, 3).Select(x => $"Added Item {x}").ToArray();
            var target = new ItemsPresenter
            {
                VirtualizationMode = ItemVirtualizationMode.None,
                Items = items,
                ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Height = 10 }),
            };

            target.ApplyTemplate();

            Assert.Equal(items.Count, target.Panel.Children.Count);

            foreach (var item in toAdd)
            {
                items.Insert(1, item);
            }

            Assert.Equal(items.Count, target.Panel.Children.Count);

            foreach (var item in toAdd)
            {
                items.Remove(item);
            }

            Assert.Equal(items.Count, target.Panel.Children.Count);
        }
예제 #9
0
        public void Removing_Items_Should_Fire_LogicalChildren_CollectionChanged()
        {
            var target = new ItemsControl();
            var items = new AvaloniaList<string> { "Foo", "Bar" };
            var called = false;

            target.Template = GetTemplate();
            target.Items = items;
            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
                called = e.Action == NotifyCollectionChangedAction.Remove;

            items.Remove("Bar");

            Assert.True(called);
        }
예제 #10
0
        public void Removing_Item_Should_Raise_CollectionChanged()
        {
            var target = new AvaloniaList<int>(new[] { 1, 2, 3 });
            var raised = false;

            target.CollectionChanged += (s, e) =>
            {
                Assert.Equal(target, s);
                Assert.Equal(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.Equal(new[] { 3 }, e.OldItems.Cast<int>());
                Assert.Equal(2, e.OldStartingIndex);

                raised = true;
            };

            target.Remove(3);

            Assert.True(raised);
        }