本文整理汇总了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);
}
});
}
示例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!"));
}
示例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!"));
}