Exemplo n.º 1
0
        public void When_ContainerStyleSet()
        {
            var count = 0;
            var panel = new StackPanel();

            var source = new ObservableVector <int>()
            {
                1, 2, 3
            };

            var SUT = new ItemsControl()
            {
                ItemsPanelRoot         = panel,
                ItemContainerStyle     = BuildBasicContainerStyle(),
                InternalItemsPanelRoot = panel,
                ItemTemplate           = new DataTemplate(() =>
                {
                    count++;
                    return(new Border());
                })
            };

            SUT.ApplyTemplate();

            Assert.AreEqual(0, count);

            SUT.ItemsSource = source;
            Assert.AreEqual(3, count);

            source.Add(4);
            Assert.AreEqual(4, count);

            source.Remove(1);
            Assert.AreEqual(4, count);
        }
Exemplo n.º 2
0
        public void When_ObservableVectorChanged()
        {
            var count = 0;
            var panel = new StackPanel();

            var source = new ObservableVector <int>()
            {
                1, 2, 3
            };

            var SUT = new ItemsControl()
            {
                ItemsPanelRoot         = panel,
                InternalItemsPanelRoot = panel,
                ItemTemplate           = new DataTemplate(() =>
                {
                    count++;
                    return(new Border());
                })
            };

            Assert.AreEqual(0, count);

            SUT.ItemsSource = source;
            Assert.AreEqual(3, count);

            source.Add(4);
            Assert.AreEqual(7, count);

            source.Remove(1);
            Assert.AreEqual(13, count);
        }
Exemplo n.º 3
0
        public void When_Item_Removed_VectorChanged()
        {
            var vector = new ObservableVector <string>()
            {
                "one", "two", "three"
            };
            var count = 0;

            vector.VectorChanged += (o, e) =>
            {
                count++;
                switch (count)
                {
                case 1:
                    Assert.AreEqual(2u, e.Index);
                    Assert.AreEqual(CollectionChange.ItemRemoved, e.CollectionChange);
                    break;

                case 2:
                    Assert.AreEqual(0u, e.Index);
                    Assert.AreEqual(CollectionChange.ItemRemoved, e.CollectionChange);
                    break;

                default:
                    Assert.Fail("Raised too many times");
                    break;
                }
            };

            vector.RemoveAt(2);
            vector.Remove("one");
        }
Exemplo n.º 4
0
        public void When_ObservableVectorStringChanged()
        {
            var count = 0;
            var panel = new StackPanel();

            var source = new ObservableVector <string>()
            {
                "1", "2", "3"
            };

            var SUT = new ItemsControl()
            {
                ItemsPanelRoot         = panel,
                InternalItemsPanelRoot = panel,
                ItemTemplate           = new DataTemplate(() =>
                {
                    count++;
                    return(new Border());
                })
            };

            Assert.AreEqual(0, count);

            SUT.ItemsSource = source;
            Assert.AreEqual(3, count);

            source.Add("4");
            Assert.AreEqual(4, count);

            source.Remove("1");
            Assert.AreEqual(4, count);

            source[0] = "5";
            // Data template is not recreated because of pooling
            Assert.AreEqual(4, count);
        }
Exemplo n.º 5
0
        public void When_ObservableVectorIntChanged()
        {
            var count = 0;
            var panel = new StackPanel();

            var source = new ObservableVector <int>()
            {
                1, 2, 3
            };

            var SUT = new ItemsControl()
            {
                ItemsPanelRoot         = panel,
                InternalItemsPanelRoot = panel,
                ItemTemplate           = new DataTemplate(() =>
                {
                    count++;
                    return(new Border());
                })
            };

            Assert.AreEqual(0, count);

            SUT.ItemsSource = source;
            Assert.AreEqual(3, count);

            source.Add(4);
            Assert.AreEqual(4, count);

            source.Remove(1);
            Assert.AreEqual(4, count);

            source[0] = 5;
            // Data template is not recreated because of pooling
            Assert.AreEqual(FrameworkTemplatePool.IsPoolingEnabled ? 4 : 5, count);
        }
Exemplo n.º 6
0
        public void When_ObservableVectorStringChanged()
        {
            var count          = 0;
            var containerCount = 0;
            var panel          = new StackPanel();

            panel.ForceLoaded();

            var source = new ObservableVector <string>()
            {
                "1", "2", "3"
            };

            Style BuildContainerStyle() =>
            new Style(typeof(Windows.UI.Xaml.Controls.ListViewItem))
            {
                Setters =
                {
                    new Setter <ContentControl>("Template",                                t =>
                                                t.Template = Funcs.Create(() => {
                        containerCount++;
                        return(new Grid
                        {
                            Children =
                            {
                                new ContentPresenter()
                                .Apply(p => {
                                    p.SetBinding(ContentPresenter.ContentTemplateProperty, new Binding()
                                    {
                                        Path = "ContentTemplate",                          RelativeSource = RelativeSource.TemplatedParent
                                    });
                                    p.SetBinding(ContentPresenter.ContentProperty,         new Binding()
                                    {
                                        Path = "Content",                                  RelativeSource = RelativeSource.TemplatedParent
                                    });
                                })
                            }
                        });
                    })
                                                )
                }
            };

            var SUT = new ListView()
            {
                ItemsPanelRoot         = panel,
                InternalItemsPanelRoot = panel,
                ItemContainerStyle     = BuildContainerStyle(),
                ItemTemplate           = new DataTemplate(() =>
                {
                    count++;
                    return(new Border());
                })
            };

            Assert.AreEqual(0, count);
            Assert.AreEqual(0, containerCount);
            Assert.AreEqual(0, containerCount);

            SUT.ItemsSource = source;
            Assert.AreEqual(3, count);
            Assert.AreEqual(3, containerCount);
            Assert.AreEqual(3, containerCount);

            source.Add("4");
            Assert.AreEqual(4, count);
            Assert.AreEqual(4, containerCount);
            Assert.AreEqual(4, containerCount);

            source.Remove("1");
            Assert.AreEqual(4, count);
            Assert.AreEqual(4, containerCount);
            Assert.AreEqual(4, containerCount);

            source[0] = "5";
            // Data template is not recreated because of pooling
            Assert.AreEqual(4, count);
            // The item container style is reapplied (not cached)
            Assert.AreEqual(5, containerCount);
        }
Exemplo n.º 7
0
        public void Remove_CollectionChanged()
        {
            List<int> collection = new List<int>(new int[] { 1, 3, 7, 10, 42 });
            ObservableVector<int> vector = new ObservableVector<int>(collection);

            bool vectorChanged = false;
            vector.CollectionChanged += (sender, e) => { if (e.Action == NotifyCollectionChangedAction.Remove && e.OldStartingIndex == 2 && (int)e.OldItems[0] == 7) { vectorChanged = true; } };

            vector.Remove(7);

            Assert.AreEqual(true, vectorChanged);
        }
Exemplo n.º 8
0
        public void Remove_PropertyChanged_Indexer()
        {
            List<int> collection = new List<int>(new int[] { 1, 3, 7, 10, 42 });
            ObservableVector<int> vector = new ObservableVector<int>(collection);

            bool propertyChanged = false;
            vector.PropertyChanged += (sender, e) => { if (e.PropertyName == "Item[]") { propertyChanged = true; } };

            vector.Remove(7);

            Assert.AreEqual(true, propertyChanged);
        }
Exemplo n.º 9
0
        public void Remove_RemoveItem()
        {
            List<int> collection = new List<int>(new int[] { 1, 3, 7, 10, 42 });
            ObservableVector<int> vector = new ObservableVector<int>(collection);

            vector.Remove(7);

            CollectionAssert.AreEqual(new int[] { 1, 3, 10, 42 }, vector.ToArray());
        }