Open a New Frame Window From MainPage in Windows 10 Universal App? -
how open new frame window contains xaml page when click button main window in universal app?
you can check out sample on how offical microsoft samples on github can found here i'll summarize here. simpler implementation can found on mike taulty's blog.
since haven't specified development language assume c# , xaml.
create button in xaml clicked create new window:
<button content="create" horizontalalignment="center" verticalalignment="center" click="oncreate" />
in code behind, add oncreate click handler:
async void oncreate(object sender, routedeventargs e) { coreapplicationview newcoreview = coreapplication.createnewview(); applicationview newappview = null; int mainviewid = applicationview.getapplicationviewidforwindow( coreapplication.mainview.corewindow); await newcoreview.dispatcher.runasync( coredispatcherpriority.normal, () => { newappview = applicationview.getforcurrentview(); window.current.content = new subwindowusercontrol(); window.current.activate(); }); await applicationviewswitcher.tryshowasstandaloneasync( newappview.id, viewsizepreference.usehalf, mainviewid, viewsizepreference.usehalf); }
this creates new window, , fetches application view id of original window reference. awaits dispatched thread run (in ui thread of new window) new view window contains adds new subwindowusercontrol
to, programatically, , activated (you must remember this). new window shown in new standalone window using standard parameters.
check out api documentation here more details on applicationviewswitcher class.
to take code , make show new xaml page can create new page , change async task running on new window in oncreate code follows:
await newcoreview.dispatcher.runasync( coredispatcherpriority.normal, () => { newappview = applicationview.getforcurrentview(); window.current.content = new frame(); (window.current.content frame).navigate(typeof(<your_page>)); window.current.activate(); });
this, instead of showing new custom xaml element content, creates new frame
navigated show xaml page.
hope helps!
Comments
Post a Comment