c# - Hot to get content from another page in uwp after a few seconds -
i have page1.xaml
<grid background="{themeresource applicationpagebackgroundthemebrush}"> <stackpanel horizontalalignment="left" height="720" verticalalignment="top" width="575"> <textblock foreground="white" textwrapping="wrap" margin="28,20,31,0" fontsize="14" height="145"> <textblock.transitions> <transitioncollection> <entrancethemetransition fromhorizontaloffset="400"/> </transitioncollection> </textblock.transitions> <run text="text 1"/> </textblock> </stackpanel> </grid>
and page2.xaml
<grid background="{themeresource applicationpagebackgroundthemebrush}"> <textblock foreground="white selectionchanged="textblock_selectionchanged" name="textblockone"> <textblock.transitions> <transitioncollection> <entrancethemetransition fromhorizontaloffset="400"/> </transitioncollection> </textblock.transitions> <run text="text 2"/> </textblock> </grid>
what want replace "text 1" in page 1 after 5 seconds "text 2" page 2.
i tried in page2.xaml.cs:
private void textblock_selectionchanged(object sender, routedeventargs e) { var test = textblockone.text; frame.navigate(typeof(page1), test); }
how solve problem?
you can use mainpage navigate it.
first, mainpage have frame can navigate apage .
then,mainpage start timer can wait 5 second call mainpage navigate bpage.
the code in xaml ,i write in mainpage
<frame x:name="frame"/>
the code in xaml.cs
public mainpage() { this.initializecomponent(); frame.navigate(typeof(apage)); dispatchertimer t = new dispatchertimer(); t.interval = new timespan(1000); t.tick += (s, e) => { navigatepageb(); }; t.start(); } private async void navigatepageb() { await coreapplication.mainview.corewindow.dispatcher.runasync(coredispatcherpriority.normal, () => { frame.navigate(typeof(pageb)); }); }
Comments
Post a Comment