在框架或文本块中导航

navigate through frame or text block

enter image description here想从包含文本块的框架导航,我正在尝试在 mainpage.xaml 和 mainpage.xaml.cs 中给出下面的代码,但 happens.please 没有任何帮助我是 uwp -app dev 的新手,有任何建议请提供

<Grid Grid.Row="2" Background="Transparent">
            <Image Source="Assets\info_footer.png"  Stretch="Fill" />
            <TextBlock  Text="Sign in" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="4,4,200,3" FontSize="32" />
            <TextBlock  Text="Sign up" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="190,4,10,3" FontSize="32"/>
            <Frame Name="MyFrame" Margin="4,4,220,3" Tapped="MyFrame_Tapped" >



            </Frame>
            <Frame Name="MyFrame1" Margin="210,4,10,3" Tapped="MyFrame1_Tapped" >

            </Frame>

namespace CustomSplash
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    /// 

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            RemoveGap();
        }
        public async void RemoveGap()
        {

            await StatusBar.GetForCurrentView().HideAsync();
        }

        private void MyFrame_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Frame.Navigate(typeof(signin));
        }

        private void MyFrame1_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Frame.Navigate(typeof(signup));
        }
    }

}

我同意@IInspectable 的评论

saying Help me learn programming" type of questions aren't useful to future visitors.

然而,我的回答将纠正您正在犯的错误,并将您推向正确的方向。

您的网格应该如下所示

<Grid Grid.Row="2" Background="Transparent">
    <Image Source="Assets\info_footer.png"  Stretch="Fill" />
    <TextBlock  Text="Sign in" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="32" Tapped="TextBlock_Tapped"/>
    <TextBlock  Text="Sign up" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="32" Tapped="TextBlock_Tapped"/>
    <Frame Name="MyFrame" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</Grid>

当您在一个带有用于显示不同视图的框架的页面中时,您不需要为每个页面使用多个框架。您可以使用单个框架进行导航。但是,我建议您直接导航到该页面,因为从用户的角度来看,当用户仍然导航到这些页面时,他们仍然会看到 Sign Up / Sign In 按钮。但如果它仍然是一个要求。你的网格应该像上面那样。

如果您看到我从框架中删除了您的 Tapped 事件并移至 TextBlock,因为这是您希望用户点击并导航到适当页面的地方。

我将 MyFrameHorizontalAlignmentVerticalAlignment 更改为 Stretch 。为什么?因为现在它将填满整个 space 而无需使用 Margin

现在开始您的点击事件。

private void MyFrame_Tapped(object sender, TappedRoutedEventArgs e)
{
    TextBlock textBlock = (TextBlock)sender;
    switch(textBlock.Text)
    {
        case "Sign in":
            MyFrame.Navigate(typeof(signin));
            break;
        case "Sign up":
            MyFrame.Navigate(typeof(signup));
            break;
    }
}

在 XAML 中,您可以看到我在两个 TextBlock 上使用了相同的点击事件。在事件本身中,我正在使用 TextBlock textBlock = (TextBlock)sender; 检查正在调用哪个 TextBlock,以便我可以获得正确的 TextBlock。由于 TextBlock Text 属性 对它们来说都是不同的,我正在使用它切换到适当的页面并导航到与 TextBlocks 相关的页面。

祝你好运,编码愉快。