コード例 #1
0
        public void Selected_Item_Changes_To_Next_First_Item_When_Item_Removed_From_Beggining_Of_List()
        {
            var items = new ObservableCollection <string>
            {
                "Foo",
                "Bar",
                "FooBar"
            };

            var target = new Carousel
            {
                Template      = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items         = items,
                IsVirtualized = false
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            Assert.Single(target.GetLogicalChildren());

            var child = target.GetLogicalChildren().Single();

            Assert.IsType <TextBlock>(child);
            Assert.Equal("Foo", ((TextBlock)child).Text);

            items.RemoveAt(0);

            child = target.GetLogicalChildren().Single();

            Assert.IsType <TextBlock>(child);
            Assert.Equal("Bar", ((TextBlock)child).Text);
        }
コード例 #2
0
        public void Selected_Item_Changes_To_First_Item_When_Items_Property_Changes()
        {
            var items = new ObservableCollection <string>
            {
                "Foo",
                "Bar",
                "FooBar"
            };

            var target = new Carousel
            {
                Template      = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items         = items,
                IsVirtualized = false
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            Assert.Equal(3, target.GetLogicalChildren().Count());

            var child = GetContainerTextBlock(target.GetLogicalChildren().First());

            Assert.Equal("Foo", child.Text);

            var newItems = items.ToList();

            newItems.RemoveAt(0);

            target.Items = newItems;

            child = GetContainerTextBlock(target.GetLogicalChildren().First());

            Assert.Equal("Bar", child.Text);
        }
コード例 #3
0
        public void Selected_Index_Changes_To_None_When_Items_Assigned_Null()
        {
            var items = new ObservableCollection <string>
            {
                "Foo",
                "Bar",
                "FooBar"
            };

            var target = new Carousel
            {
                Template      = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items         = items,
                IsVirtualized = false
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            Assert.Equal(3, target.GetLogicalChildren().Count());

            var child = GetContainerTextBlock(target.GetLogicalChildren().First());

            Assert.Equal("Foo", child.Text);

            target.Items = null;

            var numChildren = target.GetLogicalChildren().Count();

            Assert.Equal(0, numChildren);
            Assert.Equal(-1, target.SelectedIndex);
        }
コード例 #4
0
ファイル: CarouselTests.cs プロジェクト: Arlorean/Perspex
        public void LogicalChild_Should_Be_Selected_Item()
        {
            var target = new Carousel
            {
                Template = new FuncControlTemplate<Carousel>(CreateTemplate),
                Items = new[]
                {
                    "Foo",
                    "Bar"
                }
            };

            target.ApplyTemplate();

            Assert.Equal(1, target.GetLogicalChildren().Count());

            var child = target.GetLogicalChildren().Single();
            Assert.IsType<TextBlock>(child);
            Assert.Equal("Foo", ((TextBlock)child).Text);
        }
コード例 #5
0
ファイル: CarouselTests.cs プロジェクト: kekekeks/Perspex
        public void LogicalChild_Should_Be_Selected_Item()
        {
            var target = new Carousel
            {
                Template = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items    = new[]
                {
                    "Foo",
                    "Bar"
                }
            };

            target.ApplyTemplate();

            Assert.Equal(1, target.GetLogicalChildren().Count());

            var child = target.GetLogicalChildren().Single();

            Assert.IsType <TextBlock>(child);
            Assert.Equal("Foo", ((TextBlock)child).Text);
        }
コード例 #6
0
        public void LogicalChild_Should_Be_Selected_Item()
        {
            var target = new Carousel
            {
                Template = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items    = new[]
                {
                    "Foo",
                    "Bar"
                }
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            Assert.Single(target.GetLogicalChildren());

            var child = GetContainerTextBlock(target.GetLogicalChildren().Single());

            Assert.Equal("Foo", child.Text);
        }
コード例 #7
0
        public void Selected_Item_Changes_To_First_Item_When_Item_Added()
        {
            var items  = new ObservableCollection <string>();
            var target = new Carousel
            {
                Template      = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items         = items,
                IsVirtualized = false
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            Assert.Equal(-1, target.SelectedIndex);
            Assert.Empty(target.GetLogicalChildren());

            items.Add("Foo");

            Assert.Equal(0, target.SelectedIndex);
            Assert.Single(target.GetLogicalChildren());
        }
コード例 #8
0
        public void Selected_Item_Changes_To_First_Item_When_Items_Property_Changes_And_Virtualized()
        {
            var items = new ObservableCollection <string>
            {
                "Foo",
                "Bar",
                "FooBar"
            };

            var target = new Carousel
            {
                Template = new FuncControlTemplate <Carousel>(CreateTemplate),
                Items    = items
            };

            target.ApplyTemplate();
            target.Presenter.ApplyTemplate();

            Assert.Single(target.GetLogicalChildren());

            var child = target.GetLogicalChildren().Single();

            Assert.IsType <TextBlock>(child);
            Assert.Equal("Foo", ((TextBlock)child).Text);

            var newItems = items.ToList();

            newItems.RemoveAt(0);

            target.Items = newItems;

            child = target.GetLogicalChildren().Single();

            Assert.IsType <TextBlock>(child);
            Assert.Equal("Bar", ((TextBlock)child).Text);
        }