本文整理汇总了C#中ObservableCollection.WithUpdates方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.WithUpdates方法的具体用法?C# ObservableCollection.WithUpdates怎么用?C# ObservableCollection.WithUpdates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.WithUpdates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectMany_ObservableSourceSubSourceAdded_Updates
public void SelectMany_ObservableSourceSubSourceAdded_Updates()
{
var update = 0;
ICollection<Dummy<ICollection<Dummy<string>>>> coll = new ObservableCollection<Dummy<ICollection<Dummy<string>>>>();
var dummy = new Dummy<string>() { Item = "23" };
var dummy2 = new Dummy<ICollection<Dummy<string>>>()
{
Item = new List<Dummy<string>>() { dummy }
};
var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item);
test.CollectionChanged += (o, e) =>
{
update++;
Assert.AreEqual("23", e.NewItems[0]);
};
Assert.IsFalse(Sys.Contains(test, "23"));
Assert.AreEqual(0, update);
coll.Add(dummy2);
Assert.AreEqual(1, update);
Assert.IsTrue(Sys.Contains(test, "23"));
}
示例2: Linq_Test_Employees
public void Linq_Test_Employees()
{
var violation = false;
var employees = new ObservableCollection<Person>();
var employeesWithUpdates = employees.WithUpdates();
var violations = from employee in employeesWithUpdates
where employee.WorkItems > 2 *
(from collegue in employeesWithUpdates
where collegue.Team == employee.Team
select collegue.WorkItems).Average()
select employee.Name;
violations.CollectionChanged += (o, e) =>
{
violation = true;
};
Assert.IsFalse(violation);
employees.Add(new Person() { Name = "John", WorkItems = 20, Team = "A" });
Assert.IsFalse(violation);
employees.Add(new Person() { Name = "Susi", WorkItems = 5, Team = "A" });
Assert.IsFalse(violation);
employees.Add(new Person() { Name = "Joe", WorkItems = 3, Team = "A" });
Assert.IsTrue(violation);
}
示例3: SelectMany_ObservableSourceSubSourceAdded_NoUpdatesWhenDetached
public void SelectMany_ObservableSourceSubSourceAdded_NoUpdatesWhenDetached()
{
var update = false;
ICollection<Dummy<ICollection<Dummy<string>>>> coll = new ObservableCollection<Dummy<ICollection<Dummy<string>>>>();
var dummy = new Dummy<string>() { Item = "23" };
var dummy2 = new Dummy<ICollection<Dummy<string>>>()
{
Item = new List<Dummy<string>>() { dummy }
};
var test = coll.WithUpdates().SelectMany(d => d.Item, (d1, d2) => d2.Item);
test.CollectionChanged += (o, e) => update = true;
Assert.IsFalse(Sys.Contains(test, "23"));
Assert.IsFalse(update);
test.Detach();
update = false;
coll.Add(dummy2);
Assert.IsFalse(update);
test.Attach();
Assert.IsTrue(update);
Assert.IsTrue(test.Contains("23"));
update = false;
coll.Remove(dummy2);
Assert.IsTrue(update);
}
示例4: Linq_SelectMany
public void Linq_SelectMany()
{
var coll = new ObservableCollection<Dummy<IEnumerable<string>>>();
var update = false;
var dummy = new Dummy<IEnumerable<string>>()
{
Item = new List<string>() { "42" }
};
var test = from d in coll.WithUpdates()
from s in d.Item
select s.Substring(0);
test.CollectionChanged += (o, e) =>
{
update = true;
Assert.AreEqual("42", e.NewItems[0]);
};
Assert.IsFalse(test.Any());
Assert.IsFalse(update);
coll.Add(dummy);
Assert.IsTrue(update);
}
示例5: OrderBy_ObservableSourceItemAdded_NoUpdateWhenDetached
public void OrderBy_ObservableSourceItemAdded_NoUpdateWhenDetached()
{
var update = false;
var coll = new ObservableCollection<string>() { "C", "A", "D" };
var test = coll.WithUpdates().OrderBy(item => item);
test.CollectionChanged += (o, e) => update = true;
test.AssertSequence("A", "C", "D");
Assert.AreEqual(3, test.Sequences.Count());
Assert.IsFalse(update);
test.Detach();
update = false;
coll.Add("B");
Assert.IsFalse(update);
test.Attach();
Assert.IsTrue(update);
test.AssertSequence("A", "B", "C", "D");
update = false;
coll.Remove("B");
Assert.IsTrue(update);
}
示例6: LambdaIntSum_ObservableSourceItemRemoved_Updates
public void LambdaIntSum_ObservableSourceItemRemoved_Updates()
{
var update = false;
var dummy = new Dummy<int>(3);
var coll = new ObservableCollection<Dummy<int>>() { new Dummy<int>(1), new Dummy<int>(2), dummy };
var testColl = coll.WithUpdates();
var test = Observable.Expression(() => testColl.Sum(d => d.Item));
test.ValueChanged += (o, e) =>
{
update = true;
Assert.AreEqual(6, e.OldValue);
Assert.AreEqual(3, e.NewValue);
};
Assert.AreEqual(6, test.Value);
Assert.AreEqual(6, testColl.Sum(d => d.Item));
Assert.IsFalse(update);
coll.Remove(dummy);
Assert.IsTrue(update);
Assert.AreEqual(3, test.Value);
}
示例7: LambdaMax_ExistingMaxAdded_NoUpdate
public void LambdaMax_ExistingMaxAdded_NoUpdate()
{
var update = false;
var coll = new ObservableCollection<Dummy<int>>() { new Dummy<int>(1), new Dummy<int>(2), new Dummy<int>(3) };
var test = Observable.Expression(() => coll.WithUpdates().Max(d => d.Item));
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual(3, test.Value);
coll.Add(new Dummy<int>(3));
Assert.IsFalse(update);
}
示例8: Min_ExistingMinAdded_NoUpdate
public void Min_ExistingMinAdded_NoUpdate()
{
var update = false;
var coll = new ObservableCollection<int>() { 1, 2, 3 };
var test = Observable.Expression(() => coll.WithUpdates().Min());
test.ValueChanged += (o, e) => update = true;
Assert.AreEqual(1, test.Value);
coll.Add(1);
Assert.IsFalse(update);
}
示例9: Any_ItemAddedToNonEmtyCollection_NoUpdate
public void Any_ItemAddedToNonEmtyCollection_NoUpdate()
{
var update = false;
var coll = new ObservableCollection<int>() { 1 };
var test = Observable.Expression(() => coll.WithUpdates().Any());
test.ValueChanged += (o, e) => update = true;
Assert.IsTrue(test.Value);
Assert.IsFalse(update);
coll.Add(2);
Assert.IsFalse(update);
}
示例10: Where_ObservableSourceSuppressedAdded_NoUpdates
public void Where_ObservableSourceSuppressedAdded_NoUpdates()
{
var update = false;
ICollection<Dummy<bool>> coll = new ObservableCollection<Dummy<bool>>();
var dummy = new Dummy<bool>() { Item = false };
var test = coll.WithUpdates().Where(d => d.Item);
test.CollectionChanged += (o, e) => update = true;
Assert.IsFalse(Sys.Contains(test, dummy));
Assert.IsFalse(update);
coll.Add(dummy);
Assert.IsFalse(update);
Assert.IsFalse(test.Any());
}
示例11: Min_ObservableSourceNewMinAdded_Update
public void Min_ObservableSourceNewMinAdded_Update()
{
var update = false;
var coll = new ObservableCollection<int>() { 1, 2, 3 };
var test = Observable.Expression(() => coll.WithUpdates().Min());
test.ValueChanged += (o, e) =>
{
update = true;
Assert.AreEqual(1, e.OldValue);
Assert.AreEqual(0, e.NewValue);
};
Assert.AreEqual(1, test.Value);
Assert.IsFalse(update);
coll.Add(0);
Assert.IsTrue(update);
Assert.AreEqual(0, test.Value);
}
示例12: OfTypeTests_ObservableSourceItemAdded_Update
public void OfTypeTests_ObservableSourceItemAdded_Update()
{
var update = false;
var coll = new ObservableCollection<object>() { 23, "42", null };
var test = coll.WithUpdates().OfType<string>();
test.CollectionChanged += (o, e) =>
{
update = true;
Assert.AreEqual("Foo", e.NewItems[0]);
Assert.IsNull(e.OldItems);
};
test.AssertSequence("42");
Assert.IsFalse(update);
coll.Add("Foo");
Assert.IsTrue(update);
test.AssertSequence("42", "Foo");
}
示例13: Distinct_ObservableSourceNewItemAdded_Update
public void Distinct_ObservableSourceNewItemAdded_Update()
{
var update = false;
var coll = new ObservableCollection<int>() { 1, 2, 2, 3 };
var test = coll.WithUpdates().Distinct();
test.CollectionChanged += (o, e) =>
{
update = true;
Assert.IsTrue(e.NewItems.Contains(4));
Assert.IsNull(e.OldItems);
};
Assert.AreEqual(3, test.Count());
Assert.IsFalse(update);
coll.Add(4);
Assert.IsTrue(update);
Assert.AreEqual(4, test.Count());
}
示例14: Count_ObservableSourceItemAdded_Update
public void Count_ObservableSourceItemAdded_Update()
{
var update = false;
var coll = new ObservableCollection<int>() { 1, 2, 3 };
var test = Observable.Expression(() => coll.WithUpdates().Count());
test.ValueChanged += (o, e) =>
{
update = true;
Assert.AreEqual(3, e.OldValue);
Assert.AreEqual(4, e.NewValue);
};
Assert.AreEqual(3, test.Value);
Assert.IsFalse(update);
coll.Add(4);
Assert.IsTrue(update);
Assert.AreEqual(4, test.Value);
}
示例15: Where_ObservableSourceItemAdded_Updates
public void Where_ObservableSourceItemAdded_Updates()
{
var update = false;
ICollection<Dummy<bool>> coll = new ObservableCollection<Dummy<bool>>();
var dummy = new Dummy<bool>() { Item = true };
var test = coll.WithUpdates().Where(d => d.Item);
test.CollectionChanged += (o, e) =>
{
update = true;
Assert.AreEqual(dummy, e.NewItems[0]);
};
Assert.IsFalse(Sys.Any(test));
Assert.IsFalse(update);
coll.Add(dummy);
Assert.IsTrue(update);
Assert.IsTrue(Sys.Contains(test, dummy));
}