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


C# ListBox.ApplyTemplate方法代码示例

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


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

示例1: MultiSelect_RemoveSelectedItems

		public void MultiSelect_RemoveSelectedItems ()
		{
			var lb = new ListBox { SelectionMode = SelectionMode.Multiple };
			for (int i = 0; i < 5; i++)
				lb.Items.Add (new object ());

			CreateAsyncTest (lb,
				() => lb.ApplyTemplate (),
				() => {
					for (int i = 0; i < lb.Items.Count; i++)
						lb.SelectedItems.Add (lb.Items [i]);

					for (int i = 0; i < lb.Items.Count; i++)
						lb.SelectedItems.Remove (lb.Items [i]);

					for (int i = 0; i < lb.Items.Count; i++) {
						var container = (ListBoxItem) lb.ItemContainerGenerator.ContainerFromIndex (i);
						Assert.IsFalse (container.IsSelected, "#1." + i);
					}
				}
			);
		}
开发者ID:shana,项目名称:moon,代码行数:22,代码来源:ListBoxTest.cs

示例2: MultiSelect_ReplaceSelectedItem

		public void MultiSelect_ReplaceSelectedItem ()
		{
			var lb = new ListBox { SelectionMode = SelectionMode.Multiple };
			for (int i = 0; i < 5; i++)
				lb.Items.Add (new object ());

			CreateAsyncTest (lb,
				() => lb.ApplyTemplate (),
				() => {
					for (int i = 0; i < lb.Items.Count; i++)
						lb.SelectedItems.Add (lb.Items [i]);

					var container = lb.ItemContainerGenerator.ContainerFromIndex (2);
					lb.Items [2] = new object ();
					Assert.AreEqual (4, lb.SelectedItems.Count, "#1");
					Assert.IsFalse (lb.SelectedItems.Contains (lb.Items [2]), "#2");
				}
			);
		}
开发者ID:shana,项目名称:moon,代码行数:19,代码来源:ListBoxTest.cs

示例3: ICV_OneItemTwoGroups3

		public void ICV_OneItemTwoGroups3 ()
		{
			var o = new object();
			var source = new CollectionViewSource { Source = new[] { o } };
			var group = new ConcretePropertyGroupDescription {
				GroupNameFromItemFunc = (item, level, culture) => new[] { "First", "Second" }
			};

			var box = new ListBox { ItemsSource = source.View };
			CreateAsyncTest(box,
				() => {
					box.ApplyTemplate();
				}, () => {
					source.GroupDescriptions.Add(group);
					Assert.AreEqual(2, box.Items.Count, "#1");
					Assert.AreEqual(o, box.Items[0], "#2");
					Assert.AreEqual(o, box.Items[1], "#3");

					// FIXME: This assertion passes in SL but not in ML. I don't think it's hugely important.
					Assert.IsNull(box.ItemContainerGenerator.ContainerFromIndex(0), "#4");
				}, () => {
					Assert.IsNotNull(box.ItemContainerGenerator.ContainerFromIndex(0), "#5");
					Assert.AreNotSame(box.ItemContainerGenerator.ContainerFromIndex(0), box.ItemContainerGenerator.ContainerFromIndex(1), "#6");
				}
			);
		}
开发者ID:shana,项目名称:moon,代码行数:26,代码来源:ListBoxTest.cs

示例4: MultiSelect_ModifySelectedItems

		public void MultiSelect_ModifySelectedItems ()
		{
			var lb = new ListBox { SelectionMode = SelectionMode.Multiple };
			for (int i = 0; i < 5; i++)
				lb.Items.Add (new object ());

			CreateAsyncTest (lb,
				() => lb.ApplyTemplate (),
				() => {
					for (int i = 0; i < lb.Items.Count; i++) {
						var item = lb.Items [i];
						lb.SelectedItems.Add (item);
						var container = (ListBoxItem) lb.ItemContainerGenerator.ContainerFromItem (item);
						Assert.IsTrue (container.IsSelected, "#1." + i);
					}
				}
			);
		}
开发者ID:shana,项目名称:moon,代码行数:18,代码来源:ListBoxTest.cs

示例5: ICV_OneItemTwoGroups_Remove

		public void ICV_OneItemTwoGroups_Remove ()
		{
			var o = new object();
			var source = new CollectionViewSource { Source = new List<Object> { o } };
			var group = new ConcretePropertyGroupDescription {
				GroupNameFromItemFunc = (item, level, culture) => new[] { "First", "Second" }
			};

			source.GroupDescriptions.Add(group);
			var box = new ListBox { ItemsSource = source.View };
			CreateAsyncTest (box,
				() => {
					box.ApplyTemplate();
				}, () => {
					((IEditableCollectionView)source.View).RemoveAt (0);
					Assert.AreEqual (0, box.Items.Count, "#1");
				}
			);
		}
开发者ID:shana,项目名称:moon,代码行数:19,代码来源:ListBoxTest.cs


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