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
findnamemethod 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
Post a Comment