本文整理汇总了C#中ObservableCollection.SequenceEqual方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.SequenceEqual方法的具体用法?C# ObservableCollection.SequenceEqual怎么用?C# ObservableCollection.SequenceEqual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.SequenceEqual方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObservableCollectionTest
public void ObservableCollectionTest()
{
var originalCollection = new ObservableCollection<MyModel>() { new MyModel() };
var synchronizingCollection = new SynchronizingCollection<MyDataModel, MyModel>(originalCollection, m => new MyDataModel(m));
Assert.IsTrue(originalCollection.SequenceEqual(synchronizingCollection.Select(dm => dm.Model)));
// Check add operation with collection changed event.
bool handlerCalled = false;
NotifyCollectionChangedEventHandler handler = (sender, e) =>
{
handlerCalled = true;
Assert.AreEqual(synchronizingCollection, sender);
Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
Assert.AreEqual(1, e.NewStartingIndex);
Assert.AreEqual(originalCollection.Last(), e.NewItems.Cast<MyDataModel>().Single().Model);
};
synchronizingCollection.CollectionChanged += handler;
originalCollection.Add(new MyModel());
Assert.IsTrue(handlerCalled);
// After dispose the collection does not synchronize anymore
handlerCalled = false;
synchronizingCollection.Dispose();
originalCollection.Add(new MyModel());
Assert.IsFalse(handlerCalled);
synchronizingCollection.CollectionChanged -= handler;
}
示例2: SetOriginalItemsSourceShouldGetDataFromPrevious
public void SetOriginalItemsSourceShouldGetDataFromPrevious()
{
var model = new GridModel { Name = "test" };
var listItems = new List<GridModel> { model };
var viewModel = GetViewModel<GridViewModel<GridModel>>();
viewModel.UpdateItemsSource(listItems);
var newItemsSource = new ObservableCollection<GridModel>();
viewModel.SetOriginalItemsSource(newItemsSource);
newItemsSource.SequenceEqual(listItems).ShouldBeTrue();
}