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