- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
public static class ControlManager
{
public static UIElement GetControlByName(UIElement control, string name)
{
if (EntityType.GetValue(control, "Name").Equals(name))
return control;
if (EntityType.IsProperty(control, "Children"))
{
foreach (var element in (UIElementCollection)EntityType.GetValue(control, "Children"))
{
if (EntityType.GetValue(element, "Name").Equals(name))
return element;
var temp = GetControlByName(element, name);
if (temp != null)
return temp;
}
}
if (EntityType.IsProperty(control, "Child"))
{
var element = (UIElement)EntityType.GetValue(control, "Child");
if (EntityType.GetValue(element, "Name").Equals(name))
return element;
var temp = GetControlByName(element, name);
if (temp != null)
return temp;
}
if (EntityType.IsProperty(control, "SelectionElement"))
{
var element = (UIElement)EntityType.GetValue(control, "SelectionElement");
if (EntityType.GetValue(element, "Name").Equals(name))
return element;
var temp = GetControlByName(element, name);
if (temp != null)
return temp;
}
return null;
}
public static UIElement GetControlByType(UIElement control, Type type)
{
if (control.GetType() == type)
return control;
if (EntityType.IsProperty(control, "Children"))
{
foreach (var element in (UIElementCollection)EntityType.GetValue(control, "Children"))
{
if (element.GetType() == type)
return element;
var temp = GetControlByType(element, type);
if (temp != null)
return temp;
}
}
if (EntityType.IsProperty(control, "Child"))
{
var element = (UIElement)EntityType.GetValue(control, "Child");
if (element.GetType() == type)
return element;
var temp = GetControlByType(element, type);
if (temp != null)
return temp;
}
if (EntityType.IsProperty(control, "SelectionElement"))
{
var element = (UIElement)EntityType.GetValue(control, "SelectionElement");
if (element.GetType() == type)
return element;
var temp = GetControlByType(element, type);
if (temp != null)
return temp;
}
return null;
}
}
Автор тот же.
Этот код пошатнул мою психику. А может так и надо. а?
всё-таки stringly-static programming....