几秒钟后如何从uwp中的另一个页面获取内容

How to get content from another page in uwp after a few seconds

我有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>

和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>

我想要做的是在 5 秒后将第 1 页中的 "Text 1" 替换为第 2 页中的 "Text 2"。

我在 Page2.xaml.cs:

中试过这个
private void TextBlock_SelectionChanged(object sender, RoutedEventArgs e)
    {
        var test = TextBlockOne.Text;
        Frame.Navigate(typeof(Page1), test);
    }

我该如何解决这个问题?

您可以使用 MainPage 对其进行导航。

首先,MainPage 有一个可以导航到 Apage 的框架。

然后,MainPage启动一个定时器,可以等待5秒调用MainPage导航到Bpage。

xaml里的代码,我写在MainPage里

<Frame x:Name="frame"/>

代码在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));
         });
    }
 public MainPage()
{
     DispatcherTimer t = new DispatcherTimer();
     t.Interval = TimeSpan.FromSeconds(5);
     t.Tick += (s, e) =>
     {
         frame.Navigate(typeof(Page2));
         StopTimer();
     };
     t.Start();
}

 public void StopTimer()
 {
     t.Stop();
 }

Page2.xaml

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    TextBlock.Text = "My string";
}