Пример #1
0
        public void Should_Handle_Null_Items()
        {
            var items = new PerspexList <string>(new[] { "foo", null, "bar" });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();

            var text = target.Panel.Children.Cast <TextBlock>().Select(x => x.Text).ToList();

            Assert.Equal(new[] { "foo", "bar" }, text);
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(0));
            Assert.Null(target.ItemContainerGenerator.ContainerFromIndex(1));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(2));

            items.RemoveAt(1);

            text = target.Panel.Children.Cast <TextBlock>().Select(x => x.Text).ToList();

            Assert.Equal(new[] { "foo", "bar" }, text);
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(0));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(1));
        }
        public void Removing_Selected_Item_Should_Clear_Selection()
        {
            var items = new PerspexList <Item>
            {
                new Item(),
                new Item(),
            };

            var target = new SelectingItemsControl
            {
                Items    = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 1;

            Assert.Equal(items[1], target.SelectedItem);
            Assert.Equal(1, target.SelectedIndex);

            items.RemoveAt(1);

            Assert.Equal(null, target.SelectedItem);
            Assert.Equal(-1, target.SelectedIndex);
        }
        public void Selection_Should_Be_Cleared_When_No_Items_Left()
        {
            var items = new PerspexList <string>(new[] { "foo", "bar" });

            var target = new TestSelector
            {
                Items    = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 1;
            items.RemoveAt(1);
            items.RemoveAt(0);

            Assert.Equal(-1, target.SelectedIndex);
            Assert.Null(target.SelectedItem);
        }
        public void Selection_Should_Be_Cleared_When_No_Items_Left()
        {
            var items = new PerspexList<string>(new[] { "foo", "bar" });

            var target = new TestSelector
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 1;
            items.RemoveAt(1);
            items.RemoveAt(0);

            Assert.Equal(-1, target.SelectedIndex);
            Assert.Null(target.SelectedItem);
        }
Пример #5
0
        public void Control_Item_Should_Be_Removed_From_Logical_Children_Before_ApplyTemplate()
        {
            var target = new ItemsControl();
            var child = new Control();
            var items = new PerspexList<Control>(child);

            target.Template = GetTemplate();
            target.Items = items;
            items.RemoveAt(0);

            Assert.Null(child.Parent);
            Assert.Null(child.GetLogicalParent());
            Assert.Empty(target.GetLogicalChildren());
        }
Пример #6
0
        public void Should_Remove_Containers()
        {
            var items  = new PerspexList <string>(new[] { "foo", "bar" });
            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(0);

            Assert.Equal(1, target.Panel.Children.Count);
            Assert.Equal("bar", ((TextBlock)target.Panel.Children[0]).Text);
        }
Пример #7
0
        public void Should_Remove_Containers()
        {
            var items = new PerspexList<string>(new[] { "foo", "bar" });
            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(0);

            Assert.Equal(1, target.Panel.Children.Count);
            Assert.Equal("bar", ((TextBlock)target.Panel.Children[0]).Text);
        }
Пример #8
0
        public void Control_Item_Should_Be_Removed_From_Logical_Children_Before_ApplyTemplate()
        {
            var target = new ItemsControl();
            var child  = new Control();
            var items  = new PerspexList <Control>(child);

            target.Template = GetTemplate();
            target.Items    = items;
            items.RemoveAt(0);

            Assert.Null(child.Parent);
            Assert.Null(child.GetLogicalParent());
            Assert.Empty(target.GetLogicalChildren());
        }
Пример #9
0
        public void Should_Handle_Duplicate_Items()
        {
            var items = new PerspexList <int>(new[] { 1, 2, 1 });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(2);

            var text = target.Panel.Children.OfType <TextBlock>().Select(x => x.Text);

            Assert.Equal(new[] { "1", "2" }, text);
        }
        public void Item_Should_Be_Selected_When_Selection_Removed()
        {
            var items = new PerspexList <string>(new[] { "foo", "bar", "baz", "qux" });

            var target = new TestSelector
            {
                Items    = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 2;
            items.RemoveAt(2);

            Assert.Equal(2, target.SelectedIndex);
            Assert.Equal("qux", target.SelectedItem);
        }
        public void Item_Should_Be_Selected_When_Selection_Removed()
        {
            var items = new PerspexList<string>(new[] { "foo", "bar", "baz", "qux" });

            var target = new TestSelector
            {
                Items = items,
                Template = Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 2;
            items.RemoveAt(2);

            Assert.Equal(2, target.SelectedIndex);
            Assert.Equal("qux", target.SelectedItem);
        }
Пример #12
0
        public void Should_Handle_Null_Items()
        {
            var items = new PerspexList <string>(new[] { "foo", null, "bar" });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();

            var text = target.Panel.Children.OfType <TextBlock>().Select(x => x.Text).ToList();

            Assert.Equal(new[] { "foo", "bar" }, text);

            items.RemoveAt(1);

            text = target.Panel.Children.OfType <TextBlock>().Select(x => x.Text).ToList();
            Assert.Equal(new[] { "foo", "bar" }, text);
        }
Пример #13
0
        public void Removing_Selected_Item_Should_Clear_Selection()
        {
            var items = new PerspexList<Item>
            {
                new Item(),
                new Item(),
            };

            var target = new SelectingItemsControl
            {
                Items = items,
                Template = this.Template(),
            };

            target.ApplyTemplate();
            target.SelectedIndex = 1;

            Assert.Equal(items[1], target.SelectedItem);
            Assert.Equal(1, target.SelectedIndex);

            items.RemoveAt(1);

            Assert.Equal(null, target.SelectedItem);
            Assert.Equal(-1, target.SelectedIndex);
        }
Пример #14
0
        public void Should_Handle_Null_Items()
        {
            var items = new PerspexList<string>(new[] { "foo", null, "bar" });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();

            var text = target.Panel.Children.Cast<TextBlock>().Select(x => x.Text).ToList();

            Assert.Equal(new[] { "foo", "bar" }, text);
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(0));
            Assert.Null(target.ItemContainerGenerator.ContainerFromIndex(1));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(2));

            items.RemoveAt(1);

            text = target.Panel.Children.Cast<TextBlock>().Select(x => x.Text).ToList();

            Assert.Equal(new[] { "foo", "bar" }, text);
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(0));
            Assert.NotNull(target.ItemContainerGenerator.ContainerFromIndex(1));
        }
Пример #15
0
        public void Should_Handle_Duplicate_Items()
        {
            var items = new PerspexList<int>(new[] { 1, 2, 1 });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();
            items.RemoveAt(2);

            var text = target.Panel.Children.OfType<TextBlock>().Select(x => x.Text);
            Assert.Equal(new[] { "1", "2" }, text);
        }
Пример #16
0
        public void Should_Handle_Null_Items()
        {
            var items = new PerspexList<string>(new[] { "foo", null, "bar" });

            var target = new ItemsPresenter
            {
                Items = items,
            };

            target.ApplyTemplate();

            var text = target.Panel.Children.OfType<TextBlock>().Select(x => x.Text).ToList();
            Assert.Equal(new[] { "foo", "bar" }, text);

            items.RemoveAt(1);

            text = target.Panel.Children.OfType<TextBlock>().Select(x => x.Text).ToList();
            Assert.Equal(new[] { "foo", "bar" }, text);
        }