本文整理汇总了C#中ObservableList.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableList.Insert方法的具体用法?C# ObservableList.Insert怎么用?C# ObservableList.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableList
的用法示例。
在下文中一共展示了ObservableList.Insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInsertChangeNotify
public void TestInsertChangeNotify()
{
var list = new ObservableList<string>("A", "B", "C", "D");
IList<ArrayChange<string>> changes = null;
list.SubscribeArrayChange(value => { changes = value; }, "test");
int expectedIndex = 2;
list.Insert(expectedIndex, "Added");
CollectionAssert.Contains(list.Value, "Added");
CollectionAssert.AreEquivalent(new[]
{
new ArrayChange<string>(ArrayChangeType.add, "Added", expectedIndex),
new ArrayChange<string>(ArrayChangeType.remove, "C", 2),
new ArrayChange<string>(ArrayChangeType.add, "C", 3),
new ArrayChange<string>(ArrayChangeType.remove, "D", 3),
new ArrayChange<string>(ArrayChangeType.add, "D", 4),
},
(ICollection) changes);
}
示例2: When_Insert_Then_Action_Add_Raised
public void When_Insert_Then_Action_Add_Raised()
{
// Arrange
var sut = new ObservableList<int>(new[] {10, 12, 18, 100});
var results = new List<NotifyCollectionChangedEventArgs>();
var expected = new[]
{
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, 777, 3),
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, 101, 0),
};
sut.CollectionChanged += (o, e) => results.Add(e);
// Act
sut.Insert(3, 777);
sut.Insert(0, 101);
// Assert
KKAssert.AreEqualByValue(expected, results);
}
示例3: event_raised_when_item_is_inserted
public void event_raised_when_item_is_inserted()
{
var testObject = new ObservableList<int>();
var events = new List<NotifyCollectionChangedEventArgs>();
testObject.Add(1);
testObject.Add(2);
testObject.CollectionChanged += (source, args) => events.Add(args);
var itemAdded = 3;
testObject.Insert(1, itemAdded);
Assert.Equal(1, events.Count);
var ev = events[0];
Assert.Equal(NotifyCollectionChangedAction.Add, ev.Action);
Assert.Equal(itemAdded, ev.NewItems[0]);
Assert.Equal(1, ev.NewStartingIndex);
}
示例4: RemoveFiresListChangedEvent
public void RemoveFiresListChangedEvent()
{
const string expectItem = "a string to remove";
const int expectIndex = 4;
var actualItem = "";
var actualIndex = -1;
var observableList = new ObservableList<string>(new[] { "A", "B", "C", "D", "E" }.AsEnumerable());
observableList.Insert(expectIndex, expectItem);
observableList.ListChanged += (s, e) =>
{
actualItem = e.Item;
actualIndex = e.Index;
};
observableList.Remove(expectItem);
Assert.AreEqual(expectItem, actualItem);
Assert.AreEqual(expectIndex, actualIndex);
}
示例5: RemoveAtFiresListChangedEvent
public void RemoveAtFiresListChangedEvent()
{
const string expectItem = "another string to remove";
const int expectIndex = 1;
var actualItem = "";
var actualIndex = -1;
var observableList = new ObservableList<string>(new[] { "Alpha", "Bravo", "Charlie", "Delta", "Echo" }.AsEnumerable());
observableList.Insert(expectIndex, expectItem);
observableList.ListChanged += (s, e) =>
{
actualItem = e.Item;
actualIndex = e.Index;
};
observableList.RemoveAt(expectIndex);
Assert.AreEqual(expectItem, actualItem);
Assert.AreEqual(expectIndex, actualIndex);
}
示例6: InsertFiresListChangedEvent
public void InsertFiresListChangedEvent()
{
const int expectedItem = 68030;
var actualItem = -1;
var actualIndex = -1;
var observableList = new ObservableList<int> { 1, 2, 4, 8 };
observableList.ListChanged += (s, e) =>
{
actualItem = e.Item;
actualIndex = e.Index;
};
observableList.Insert(3, expectedItem);
Assert.AreEqual(expectedItem, actualItem);
Assert.AreEqual(3, actualIndex);
}
示例7: TestInsert
public void TestInsert()
{
var list = new List<string> { "aaa", "bbb", "ccc" };
var set = new ObservableList<string>(list);
Assert.AreEqual(set.Count, list.Count);
bool propertyChangedInvoked = false;
bool collectionChangedInvoked = false;
set.PropertyChanged += (sender, e) =>
{
Assert.AreEqual(e.PropertyName, nameof(ObservableList<string>.Count));
propertyChangedInvoked = true;
};
set.CollectionChanged += (sender, e) =>
{
Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Add);
Assert.AreEqual(e.NewStartingIndex, 1);
Assert.NotNull(e.NewItems);
Assert.AreEqual(e.NewItems.Count, 1);
Assert.AreEqual(e.NewItems[0], "ddd");
collectionChangedInvoked = true;
};
set.Insert(1, "ddd");
Assert.AreEqual(set.Count, 4);
Assert.AreEqual(set[0], "aaa");
Assert.AreEqual(set[1], "ddd");
Assert.AreEqual(set[2], "bbb");
Assert.AreEqual(set[3], "ccc");
Assert.True(propertyChangedInvoked);
Assert.True(collectionChangedInvoked);
}