本文整理汇总了C#中ObservableCollectionEx.Single方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollectionEx.Single方法的具体用法?C# ObservableCollectionEx.Single怎么用?C# ObservableCollectionEx.Single使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollectionEx
的用法示例。
在下文中一共展示了ObservableCollectionEx.Single方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateToMatchUpdatesChangedItems
public void UpdateToMatchUpdatesChangedItems()
{
var oc = new ObservableCollectionEx<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 2),
new CollectionItem("Third", 3)
};
var toChange = new List<CollectionItem>
{
new CollectionItem("First", 100),
new CollectionItem("Second", 200),
new CollectionItem("Third", 3)
};
Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) =>
{
if (i1.Value != i2.Value)
{
i1.Value = i2.Value;
return true;
}
return false;
};
oc.UpdateToMatch(toChange, i => i.Key, updateAction);
oc.Single(i => i.Key == "First").Value.Should().Be(100);
oc.Single(i => i.Key == "Second").Value.Should().Be(200);
oc.Single(i => i.Key == "Third").Value.Should().Be(3);
}
示例2: UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreAddedRemovedAndUpdated
public void UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreAddedRemovedAndUpdated()
{
var oc = new ObservableCollectionEx<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 2),
new CollectionItem("Third", 3)
};
var toChange = new List<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 200),
new CollectionItem("Fourth", 4)
};
Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) =>
{
if (i1.Value != i2.Value)
{
i1.Value = i2.Value;
return true;
}
return false;
};
var itemCount = 0;
var eventCount = 0;
var action = NotifyCollectionChangedAction.Add;
oc.CollectionChanged += (sender, args) =>
{
++eventCount;
itemCount = oc.Count;
action = args.Action;
};
oc.UpdateToMatch(toChange, i => i.Key, updateAction).Should().BeTrue();
itemCount.Should().Be(3);
eventCount.Should().Be(1);
action.Should().Be(NotifyCollectionChangedAction.Reset);
oc.Single(i => i.Key == "First").Value.Should().Be(1);
oc.Single(i => i.Key == "Second").Value.Should().Be(200);
oc.Single(i => i.Key == "Fourth").Value.Should().Be(4);
}