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:

  1. which of above methods best?
  2. 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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -