Beispiel #1
0
        public void OnItemsChanged()
        {
            ItemsControlPoker ic = new ItemsControlPoker();

            Assert.AreEqual(0, ic.ItemAdded, "ItemAdded-0");

            ic.Items.Add("string");
            Assert.AreEqual(1, ic.ItemAdded, "ItemAdded-1");
            Assert.AreEqual(NotifyCollectionChangedAction.Add, ic.EventArgs.Action, "Action-1");
            Assert.AreEqual("string", ic.EventArgs.NewItems [0], "NewItems-1");
            Assert.AreEqual(0, ic.EventArgs.NewStartingIndex, "NewStartingIndex-1");
            Assert.IsNull(ic.EventArgs.OldItems, "OldItems-1");
            Assert.AreEqual(-1, ic.EventArgs.OldStartingIndex, "OldStartingIndex-1");

            ic.Items.Insert(0, this);
            Assert.AreEqual(2, ic.ItemAdded, "ItemAdded-2");
            Assert.AreEqual(NotifyCollectionChangedAction.Add, ic.EventArgs.Action, "Action-2");
            Assert.AreEqual(this, ic.EventArgs.NewItems [0], "NewItems-2");
            Assert.AreEqual(0, ic.EventArgs.NewStartingIndex, "NewStartingIndex-2");
            Assert.IsNull(ic.EventArgs.OldItems, "OldItems-2");
            Assert.AreEqual(-1, ic.EventArgs.OldStartingIndex, "OldStartingIndex-2");

            Assert.AreEqual(0, ic.ItemRemove, "ItemRemove");
            Assert.IsTrue(ic.Items.Remove("string"), "Remove");
            Assert.AreEqual(1, ic.ItemRemove, "ItemRemove-3");
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, ic.EventArgs.Action, "Action-3");
            Assert.IsNull(ic.EventArgs.NewItems, "NewItems-3");
            Assert.AreEqual(-1, ic.EventArgs.NewStartingIndex, "NewStartingIndex-3");
            Assert.AreEqual("string", ic.EventArgs.OldItems [0], "OldItems-3");
            Assert.AreEqual(1, ic.EventArgs.OldStartingIndex, "OldStartingIndex-3");

            ic.Items.RemoveAt(0);
            Assert.AreEqual(2, ic.ItemRemove, "ItemRemove-4");
            Assert.AreEqual(NotifyCollectionChangedAction.Remove, ic.EventArgs.Action, "Action-4");
            Assert.IsNull(ic.EventArgs.NewItems, "NewItems-4");
            Assert.AreEqual(-1, ic.EventArgs.NewStartingIndex, "NewStartingIndex-4");
            Assert.AreEqual(this, ic.EventArgs.OldItems [0], "OldItems-4");
            Assert.AreEqual(0, ic.EventArgs.OldStartingIndex, "OldStartingIndex-4");

            ic.Items.Add("string");
            Assert.AreEqual(3, ic.ItemAdded, "ItemAdded-5");

            Assert.AreEqual(0, ic.ItemReplace, "ItemReplace");
            ic.Items [0] = this;
            Assert.AreEqual(1, ic.ItemReplace, "ItemReplace-6");
            Assert.AreEqual(NotifyCollectionChangedAction.Replace, ic.EventArgs.Action, "Action-6");
            Assert.AreEqual(this, ic.EventArgs.NewItems [0], "NewItems-6");
            Assert.AreEqual(0, ic.EventArgs.NewStartingIndex, "NewStartingIndex-6");
            Assert.AreEqual("string", ic.EventArgs.OldItems [0], "OldItems-6");
            Assert.AreEqual(-1, ic.EventArgs.OldStartingIndex, "OldStartingIndex-6");

            Assert.AreEqual(0, ic.ItemReset, "ItemReset");
            ic.Items.Clear();
            Assert.AreEqual(1, ic.ItemReset, "ItemReset-7");
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, ic.EventArgs.Action, "Action-7");
            Assert.IsNull(ic.EventArgs.NewItems, "NewItems-7");
            Assert.AreEqual(-1, ic.EventArgs.NewStartingIndex, "NewStartingIndex-7");
            Assert.IsNull(ic.EventArgs.OldItems, "OldItems-7");
            Assert.AreEqual(-1, ic.EventArgs.OldStartingIndex, "OldStartingIndex-7");
        }
Beispiel #2
0
        public void ContainerItemTest7_sl4()
        {
            // Force all elements to *not* be their own container
            ItemsControlPoker c = new ItemsControlPoker {
                IsOwnContainer = false
            };

            c.ApplyTemplate();

            CreateAsyncTest(c, () => {
                ContentPresenter item;
                object content;

                content = new Rectangle();
                c.Items.Add(content);
                Assert.IsInstanceOfType <ContentPresenter> (c.LastCreatedContainer, "#1");
                item = (ContentPresenter)c.LastCreatedContainer;
                Assert.AreEqual(content, item.Content, "#2");
                Assert.IsNull(item.DataContext, "#3");

                c.LastCreatedContainer = null;

                content = "I'm a string";
                c.Items.Add(content);
                Assert.IsInstanceOfType <ContentPresenter> (c.LastCreatedContainer, "#4");
                item = (ContentPresenter)c.LastCreatedContainer;
                Assert.AreEqual(content, item.Content, "#5");
                Assert.AreEqual(content, item.DataContext, "#6");
            });
        }
Beispiel #3
0
        public void OnItemsChanged_Reset()
        {
            ItemsControlPoker c = new ItemsControlPoker();

            c.Items.Add(new object());
            c.OnItemsChanged_(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            Assert.AreEqual(1, c.Items.Count, "#1");
        }
Beispiel #4
0
        public virtual void IsItemItsOwnContainerTest()
        {
            ItemsControlPoker ic = new ItemsControlPoker();

            Assert.IsFalse(ic.IsItemItsOwnContainerOverride_(null), "null");
            Assert.IsFalse(ic.IsItemItsOwnContainerOverride_(new OpenFileDialog()), "OpenFileDialog");
            Assert.IsFalse(ic.IsItemItsOwnContainerOverride_(ic.Items), "ItemCollection");
            Assert.IsFalse(ic.IsItemItsOwnContainerOverride_(new RowDefinition()), "RowDefinition");
        }
 public virtual void Initialize()
 {
     Control            = new ItemsControlPoker();
     Control.ItemsPanel = CreateVirtualizingPanel();
     for (int i = 0; i < 5; i++)
     {
         Control.Items.Add(i.ToString());
     }
 }
Beispiel #6
0
        public void ContainerItemTest5()
        {
            ConceteElement    item = new ConceteElement();
            ItemsControlPoker c    = new ItemsControlPoker();

            c.ApplyTemplate();
            CreateAsyncTest(c, () => {
                c.Items.Add(item);
                Assert.IsNull(c.LastCreatedContainer, "#1");                  // No autogenerated container
                Assert.IsNull(item.DataContext, "#3");
            });
        }
Beispiel #7
0
        public void ClearTwiceTest()
        {
            ItemsControlPoker poker = new ItemsControlPoker();

            poker.Items.Add(new object());
            CreateAsyncTest(poker, () => {
                poker.Items.Clear();
                Assert.IsNotNull(poker.EventArgs, "#1");

                poker.EventArgs = null;
                poker.Items.Clear();
                Assert.IsNotNull(poker.EventArgs, "#2");
            });
        }
Beispiel #8
0
        public void ContainerItemTest6()
        {
            object            item      = new object();
            ConceteElement    container = new ConceteElement();
            ItemsControlPoker c         = new ItemsControlPoker();

            c.ContainerItem = container;
            c.ApplyTemplate();
            CreateAsyncTest(c, () => {
                c.Items.Add(item);
                Assert.AreEqual(container, c.LastCreatedContainer, "#1");
                Assert.AreEqual(container.DataContext, item, "#2");
                Assert.AreEqual(container.ReadLocalValue(FrameworkElement.DataContextProperty), item, "#3");
            });
        }
Beispiel #9
0
        public void OnItemsChanged_Null()
        {
            ItemsControlPoker ic = new ItemsControlPoker();

            ic.OnItemsChanged_(null);
        }
Beispiel #10
0
 public void Initialize()
 {
     Control = new ItemsControlPoker();
 }