当前位置: 首页>>代码示例>>C#>>正文


C# ListBox.GetContainers方法代码示例

本文整理汇总了C#中ListBox.GetContainers方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.GetContainers方法的具体用法?C# ListBox.GetContainers怎么用?C# ListBox.GetContainers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListBox的用法示例。


在下文中一共展示了ListBox.GetContainers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetContainers

        public virtual void GetContainers()
        {
            ListBox control = new ListBox { ItemsSource = new[] { 1, 2, 3, 4, 5 } };
            IEnumerable<DependencyObject> containers = null;
            IEnumerable<ListBoxItem> items = null;
            List<DependencyObject> allContainers = null;
            List<ListBoxItem> allItems = null;

            TestAsync(
                control,
                () => containers = control.GetContainers(),
                () => items = control.GetContainers<ListBoxItem>(),
                () => Assert.IsNotNull(containers, "containers should not be null!"),
                () => allContainers = new List<DependencyObject>(containers),
                () => Assert.AreEqual(5, allContainers.Count, "containers should have 5 items!"),
                () => Assert.IsNotNull(items, "items should not be null!"),
                () => allItems = new List<ListBoxItem>(items),
                () => Assert.AreEqual(5, allItems.Count, "items should have 5 items!"),
                () =>
                {
                    for (int i = 0; i < allItems.Count; i++)
                    {
                        Assert.AreEqual(allItems[i], allContainers[i], "Container {0} does not match item {0}!", i);
                    }
                },
                () =>
                {
                    for (int i = 0; i < allItems.Count; i++)
                    {
                        Assert.AreEqual(i + 1, control.ItemContainerGenerator.ItemFromContainer(allItems[i]), "Container {0} does not map to the correct item!", i);
                    }
                });
        }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:33,代码来源:ItemsControlExtensionsTest.cs

示例2: GetContainersWrongType

        public virtual void GetContainersWrongType()
        {
            ListBox control = new ListBox { ItemsSource = new[] { 1, 2, 3, 4, 5 } };

            TestAsync(
                control,
                () => Assert.IsFalse(control.GetContainers<TreeViewItem>().Any(t => t != null), "All items should have been null!"));
        }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:8,代码来源:ItemsControlExtensionsTest.cs

示例3: GetContainersNoItems

        public virtual void GetContainersNoItems()
        {
            ListBox control = new ListBox();
            IEnumerable<DependencyObject> containers = null;
            IEnumerable<ListBoxItem> items = null;

            TestAsync(
                control,
                () => containers = control.GetContainers(),
                () => items = control.GetContainers<ListBoxItem>(),
                () => Assert.IsNotNull(containers, "containers should not be null!"),
                () => Assert.AreEqual(0, containers.Count(), "containers should be empty!"),
                () => Assert.IsNotNull(items, "items should not be null!"),
                () => Assert.AreEqual(0, items.Count(), "items should be empty!"));
        }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:15,代码来源:ItemsControlExtensionsTest.cs


注:本文中的ListBox.GetContainers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。