本文整理汇总了C#中ObservableCollection.AsObservableQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.AsObservableQuery方法的具体用法?C# ObservableCollection.AsObservableQuery怎么用?C# ObservableCollection.AsObservableQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.AsObservableQuery方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectTest
public void SelectTest()
{
var c = new ObservableCollection<string>()
{
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
};
var q = c.AsObservableQuery()
.Select(i => new { Value = i })
.AsObservableQuery()
.ToObservableView();
q.CollectionChanged += q_CollectionChanged;
Assert.AreEqual(q.Count(), 5);
c.Add("TestItem1");
Assert.AreEqual(1, added);
Assert.AreEqual(6, q.Count());
c.Remove("TestItem1");
Assert.AreEqual(1, removed);
Assert.AreEqual(5, q.Count());
}
示例2: SetupFilters
public void SetupFilters()
{
one = new ObservableCollection<string>() { "a", "b", "c", "d" };
two = new ObservableCollection<string>() { "b", "c", "d", "e" };
buffer = one.AsObservableQuery().Intersect(two).AsObservableQuery().ToObservableView().ToBuffer();
}
示例3: ValueTest
public void ValueTest()
{
var c = new ObservableCollection<string>()
{
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
};
var v = c.AsObservableQuery()
.Observe(i => i.Count());
v.ValueChanged += v_ValueChanged;
Assert.AreEqual(5, v.Value);
c.Add("Item6");
Assert.AreEqual(6, v.Value);
c.Remove("Item1");
Assert.AreEqual(5, v.Value);
Assert.AreEqual(2, called);
}
示例4: OrderIsPreservedWhenAddingToFirstCollection
public void OrderIsPreservedWhenAddingToFirstCollection()
{
var c1 = new ObservableCollection<string>() { "b" };
var c2 = new ObservableCollection<string>() { "c", };
var combined = c1.AsObservableQuery().Concat(c2).AsObservableQuery().ToObservableView().ToBuffer();
c1.Insert(0, "a");
Assert.AreEqual("abc", string.Join("", combined));
}
示例5: AverageTest
public void AverageTest()
{
var c = new ObservableCollection<int>()
{
1,2,3,
};
var q = c.AsObservableQuery()
.Observe(i => ((IEnumerable<int>)i).Average());
}
示例6: AnyTest
public void AnyTest()
{
var c = new ObservableCollection<string>()
{
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
};
var b1 = c.AsObservableQuery()
.Any();
Assert.IsTrue(b1);
var b2 = c.AsObservableQuery()
.Where(i => i.StartsWith("B"))
.Any();
Assert.IsFalse(b2);
}
示例7: MinTest
public void MinTest()
{
var c = new ObservableCollection<int>()
{
1,
2,
};
var b1 = c.AsObservableQuery()
.Observe(i => i.Min());
Assert.AreEqual(1, b1.Value);
c.RemoveAt(0);
Assert.AreEqual(2, b1.Value);
}
示例8: CountTest
public void CountTest()
{
var c = new ObservableCollection<string>()
{
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
};
var b1 = c.AsObservableQuery()
.Observe(i => i.Count());
Assert.AreEqual(5, b1.Value);
c.RemoveAt(0);
Assert.AreEqual(4, b1.Value);
}
示例9: ConcatTest
public void ConcatTest()
{
int changes = 0;
var c1 = new ObservableCollection<string>()
{
"Item_1_1",
"Item_1_2",
"Item_1_3",
"Item_1_4",
"Item_1_5",
};
var c2 = new ObservableCollection<string>()
{
"Item_2_1",
"Item_2_2",
"Item_2_3",
"Item_2_4",
"Item_2_5",
};
var q = c1.AsObservableQuery()
.Concat(c2)
.AsObservableQuery()
.ToObservableView();
q.CollectionChanged += (s, a) => changes++;
Assert.AreEqual(q.Count(), 10);
c1.Add("Item_1_6");
Assert.AreEqual(1, changes);
Assert.AreEqual(q.Count(), 11);
c1.Remove("Item_1_6");
Assert.AreEqual(2, changes);
Assert.AreEqual(q.Count(), 10);
c1.Add("Item_2_6");
Assert.AreEqual(3, changes);
Assert.AreEqual(q.Count(), 11);
c1.Remove("Item_2_6");
Assert.AreEqual(4, changes);
Assert.AreEqual(q.Count(), 10);
}
示例10: WhereBufferTest
public void WhereBufferTest()
{
var c = new ObservableCollection<string>() { "a", "b", "c", "b", "c", "a"};
var buffer = c.AsObservableQuery().Where(i => i != "a")
.AsObservableQuery()
.ToObservableView()
.ToBuffer();
Assert.AreEqual("bcbc", string.Join("", buffer));
c.Insert(0, "a");
Assert.AreEqual("bcbc", string.Join("", buffer));
c.Insert(0, "c");
Assert.AreEqual("cbcbc", string.Join("", buffer));
c.Insert(4, "b");
Assert.AreEqual("cbcbcb", string.Join("", buffer));
}
示例11: SelectManyTest
public void SelectManyTest()
{
var c = new ObservableCollection<ObservableCollection<string>>()
{
new ObservableCollection<string>() { "Item1", "Item2" },
new ObservableCollection<string>() { "Item3", "Item4" },
new ObservableCollection<string>() { "Item5", "Item6" },
};
var q = c.AsObservableQuery()
.SelectMany(i => i)
.AsObservableQuery()
.ToObservableView();
q.CollectionChanged += q_CollectionChanged;
Assert.AreEqual(6, q.Count());
c[0].Add("Item2.5");
Assert.AreEqual(7, q.Count());
c[0].Remove("Item2.5");
Assert.AreEqual(6, q.Count());
}
示例12: SetupFilters
public void SetupFilters()
{
source = new ObservableCollection<string>("0123456789".Select(i => i.ToString()));
buffer = source.AsObservableQuery().Take(5).AsObservableQuery().ToObservableView().ToBuffer();
}
示例13: WhereTest
public void WhereTest()
{
var c = new ObservableCollection<string>()
{
"False",
"False",
"True",
"False",
"False",
};
int changed = 0;
var q = c.AsObservableQuery()
.Where(i => i == "True")
.AsObservableQuery()
.ToObservableView();
q.CollectionChanged += (s, a) => changed++;
Assert.AreEqual(1, q.Count());
c.Add("True");
Assert.AreEqual(1, changed);
Assert.AreEqual(2, q.Count());
c.Remove("True");
Assert.AreEqual(2, changed);
Assert.AreEqual(1, q.Count());
}
示例14: OrderIsPreservedWhenRemovingFromFirstCollection
public void OrderIsPreservedWhenRemovingFromFirstCollection()
{
var c1 = new ObservableCollection<string>() { "a", "b" };
var c2 = new ObservableCollection<string>() { "a", "b", };
var combined = c1.AsObservableQuery().Concat(c2).AsObservableQuery().ToObservableView().ToBuffer();
c1.RemoveAt(0);
Assert.AreEqual("bab", string.Join("", combined));
}