コード例 #1
0
ファイル: BehaviorTests.cs プロジェクト: liuact1986/MvvmLib
        public void SelectionSyncBehavior_On_Attach_With_SelectedItem()
        {
            var c = new TestSelectionSyncBehavior();

            var tabControl = new TabControl {
            };
            var i1         = new SelectItem {
                Name = "A"
            };
            var i2 = new SelectItem {
                Name = "B"
            };
            var i3 = new SelectItem {
                Name = "C"
            };

            tabControl.Items.Add(i1);
            tabControl.Items.Add(i2);
            tabControl.Items.Add(i3);

            tabControl.SelectedItem = i2;

            c.Attach(tabControl);

            Assert.AreEqual(false, i1.IsSelected);
            Assert.AreEqual(true, i2.IsSelected);
            Assert.AreEqual(false, i3.IsSelected);
        }
コード例 #2
0
ファイル: BehaviorTests.cs プロジェクト: liuact1986/MvvmLib
        public void SelectionSyncBehavior_Fails_With_Non_Selector()
        {
            var c = new TestSelectionSyncBehavior();

            var itemsControl = new ItemsControl {
            };
            var i1           = new SelectItem {
                Name = "A"
            };
            var i2 = new SelectItem {
                Name = "B"
            };
            var i3 = new SelectItem {
                Name = "C"
            };

            itemsControl.Items.Add(i1);
            itemsControl.Items.Add(i2);
            itemsControl.Items.Add(i3);

            bool failed = false;

            try
            {
                c.Attach(itemsControl);
            }
            catch (Exception)
            {
                failed = true;
            }

            Assert.AreEqual(true, failed);
        }
コード例 #3
0
ファイル: BehaviorTests.cs プロジェクト: liuact1986/MvvmLib
        public void SelectionSyncBehavior_On_Attach_With_Multiple_SelectedItems_ListBox()
        {
            var c = new TestSelectionSyncBehavior();

            var listBox = new ListBox {
                SelectionMode = SelectionMode.Multiple
            };
            var i1 = new SelectItem {
                Name = "A"
            };
            var i2 = new SelectItem {
                Name = "B"
            };
            var i3 = new SelectItem {
                Name = "C"
            };

            listBox.Items.Add(i1);
            listBox.Items.Add(i2);
            listBox.Items.Add(i3);

            listBox.SelectedItems.Add(i1);
            listBox.SelectedItems.Add(i2);

            c.Attach(listBox);

            Assert.AreEqual(true, i1.IsSelected);
            Assert.AreEqual(true, i2.IsSelected);
            Assert.AreEqual(false, i3.IsSelected);
        }