c# - Access control in content control from main window -
i had found methods access main window usercontrol:
- window parentwindow = window.getwindow(this);
- dependencyobject parentwindow = visualtreehelper.getparent(child);
- application.current.mainwindow parentwindow;
i have questions:
- which of above methods best?
- how can access control in usercontrol main window , usercontrol usercontrol in same main window?
thanks, skip bad english :)
current.mainwindow
ideal in every case because if usercontrol
embedded inside usercontrol
, can still use current.mainwindow
traversing tree. methods fine , depends on usage , you're trying accomplish.
to access control (lets textblock) inside usercontrol
.
textblock tb = findvisualchildren<textblock>(usercontrol) public static ienumerable<t> findvisualchildren<t>(dependencyobject depobj) t : dependencyobject { if (depobj != null) { (int = 0; < visualtreehelper.getchildrencount(depobj); i++) { dependencyobject child = visualtreehelper.getchild(depobj, i); if (child != null && child t) { yield return (t)child; } foreach (t childofchild in findvisualchildren<t>(child)) { yield return childofchild; } } } }
Comments
Post a Comment