How to reference a control on windows phone main page from any other non UI class? -


i thought access control on main page non ui class in same namespace using

            var frame = application.current.rootvisual phoneapplicationframe;             var startpage = frame.content phoneapplicationpage;  

but intellisense doesn't show control.

didn't find on google that's weird.

if want access control class, can either:

  • use findname method retrieve it:

    var mybutton = (button)startpage.findname("mybutton"); 
  • expose control public property, , cast page strong type rather phoneapplicationpage:

    in manpage.xaml.cs:

    public button mybutton {         {         return this.mybutton;     } } 

    in other class:

    var frame = (phoneapplicationframe)application.current.rootvisual; var startpage = (mainpage)frame.content;   // here, can use startpage.mybutton 

note accessing ui control outside of page bad idea. may want re-think application's architecture rather doing (the mvvm pattern can instance).


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -