Jordan, I'm writing a general purpose "dashboard" where it can be populated
with various charts, pickers, panels etc in different ways. I ask for blocks
of XML to feed into the various controls, so it's all rather flexible and
dynamic. I have to match the "id" of a block of XML to a child control
(somewhere down the tree) with a matching "id" and pass it the XML to
render. I was wondering how binding could used in this situation, but rather
than create some obtuse but lovely wedding cake binding library, in haste I
decided to just find the child and shove the XML into it (10 lines of code).
If this thing goes live then I'll go back to making a nice cake out of it.
I eventually decided I like this bit of code for enumerating children of a
certain type (can it be made better?)
public static IEnumerable<T> GetVisuals<T>(this DependencyObject root) where
T : DependencyObject
{
int count = VisualTreeHelper.GetChildrenCount(root);
for (int i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(root, i);
if (child is T)
{
yield return (T)child;
}
foreach (var descendants in child.GetVisuals<T>())
{
yield return descendants;
}
}
}
As an aside: I said several months ago that making general purpose utility
routines enumerable is vitally important ... so you can parallelise them.
Back then I had a file scanning routine which ran for 40 minutes or so, when
I used DirectoryInfo.EnumerateFiles with Parallel.For it took less than 10
minutes.
Greg
_______________________________________________
ozsilverlight mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight