In WPF app I use LINQ query to get values from ObservableCollection and update the state of some objects:
var shava = from clc in _ShAvaQuCollection where clc.xyID == "x02y02" select clc;
switch (shava.First().Status)
{
case 1:
x02y02.Status = MyCustControl.Status.First;
break;
case 2:
x02y02.Status = MyCustControl.Status.Second;
break;
...
}
In fact, xyID
is unique field in this ObservableCollection and its string value corresponds to names of objects in XAML (these objects are derived from a customer control MyCustControl
).
What I am trying to do is:
(1) to iterate through all of the records in _ShAvaQuCollection
and, using xyID
field, reference each particular objects, using shava
as a result of query to each of the record:
MyCustControl sc = (MyCustControl)this.FindName(shava.First().xyID);
(2) and update the state of the object, using other values from this record, for example:
switch (shava.First().Status)
{
case 1:
sc.Status = MyCustControl.Status.First;
break;
case 2:
sc.Status = MyCustControl.Status.Second;
break;
...
}
All these actions apart work well, but I cannot combine it to a working iteration method, something like this (it is an idea only, because I didn't manage to get a compyleable code):
public void ReadingCollection(System.Collections.Generic.IEnumerable<ShowAvaQu> coll)
{
foreach (var xyid in coll)
{
//do my actions (1) and (2)
}
}
Please, help me to organize such an iteration in this last piece of code inside the foreach loop. I'm experiencing problems with understanding how to make a query to each particular record of the collection inside the loop.
I described that all above just to make clear what I intend to do with results of such query inside this loop.