Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 帧导航_C#_Navigation_Controls_Uwp_Frame - Fatal编程技术网

C# 帧导航

C# 帧导航,c#,navigation,controls,uwp,frame,C#,Navigation,Controls,Uwp,Frame,我在UWP中的导航系统有问题 我有3个不同的页面,其中包含BackRequested事件。 问题是框架无法返回到第二页 例如: Page 1 -> Page 2 -> Page 3 -> BACKBUTTON -> Page 1 我想访问第2页而不是第一页 因为我想有一个导航栏,所以我决定创建一个包含框架控件的母版页。此控件称为“层” 我可以使用此代码导航到第2页 Layer.Navigate(typeof(BlankPage2), this); “this”包含整个

我在UWP中的导航系统有问题

我有3个不同的页面,其中包含BackRequested事件。 问题是框架无法返回到第二页

例如:

Page 1 -> Page 2 -> Page 3 -> BACKBUTTON -> Page 1
我想访问第2页而不是第一页

因为我想有一个导航栏,所以我决定创建一个包含框架控件的母版页。此控件称为“层”

我可以使用此代码导航到第2页

Layer.Navigate(typeof(BlankPage2), this);
“this”包含整个第一页,我需要从第二页访问该层

当我想调用第3页时,代码如下

_FirstPage.Layer.Navigate(BlankPage2),this);
我可以使用

 protected async override void OnNavigatedTo(NavigationEventArgs e)
    {FirstPage _FirstPage = e.Parameter as FirstPage;}
我认为问题在于我的第一页实例与第二页中给定的参数不同

我可以试着打第一页(比如

但是我不知道如何打开页面

这个标准是什么

如何在一个页面中使用不同页面的导航栏

我对语法感到抱歉。由于Windows 10支持键盘输入,它会尝试更正从英语到德语的任何wor
enter code here
d

*编辑

我试图创建一个测试项目,看看它在没有UIElement(框架)的情况下是如何工作的 我能够得到正确的回退。但不幸的是,问题没有解决

   protected async override void OnNavigatedTo(NavigationEventArgs e)
    {


        try
        {
            int count = 0;
            StringBuilder sb = new StringBuilder();
            foreach (var item in this.Frame.BackStack)
            {

                count++;
                sb.AppendLine(item.SourcePageType.FullName + " " + count.ToString());


            }
            MessageDialog md = new MessageDialog(sb.ToString());
            await md.ShowAsync();
        }
        catch
        {

        }


        var currentView = SystemNavigationManager.GetForCurrentView();
        currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
        currentView.BackRequested += CurrentView_BackRequested;



    }

    private void CurrentView_BackRequested(object sender, BackRequestedEventArgs e)
    {
        if (this.Frame.CanGoBack == true) { this.Frame.GoBack();}
    }
    public BlankPage3()
    {
        this.InitializeComponent();
    }

这是我的主要代码

  Sites.ContentPage cp = new Sites.ContentPage();
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        Classes.Transmission.Passwort.CreateTransmissionPasswort ctp = e.Parameter as Classes.Transmission.Passwort.CreateTransmissionPasswort;
        this.PW = ctp.PW;
        this.cp = ctp.CP;

        try
        {
            int count = 0;
            StringBuilder sb = new StringBuilder();
            foreach (var item in cp.Layer.BackStack)
            {

                count++;
                sb.AppendLine(item.SourcePageType.FullName + " " + count.ToString());


            }
            MessageDialog md = new MessageDialog(sb.ToString());
            await md.ShowAsync();
        }
        catch
        {

        }







        var currentView = SystemNavigationManager.GetForCurrentView();
        currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
        currentView.BackRequested += CurrentView_BackRequested1;
        if(Classes.CheckScreenState.GetFactorType() == Classes.CheckScreenState.DeviceForFactorType.Phone)
        {
            HardwareButtons.BackPressed += HardwareButtons_BackPressed;
        }
        if (Classes.CheckScreenState.GetFactorType() != Classes.CheckScreenState.DeviceForFactorType.Phone)
        {
            Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
        }

        }

    private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
    {
        if (args.CurrentPoint.Properties.IsXButton1Pressed)
        {
            if (cp.Layer.CanGoBack == true) { cp.Layer.GoBack(); }
            var currentView = SystemNavigationManager.GetForCurrentView();
            currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

        }
        if (args.CurrentPoint.Properties.IsXButton2Pressed)
        {
            if (cp.Layer.CanGoForward == true) { cp.Layer.GoForward(); }
            var currentView = SystemNavigationManager.GetForCurrentView();
            currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

        }
    }

    private void CurrentView_BackRequested1(object sender, BackRequestedEventArgs e)
    {
        if (cp.Layer.CanGoBack == true) {cp.Layer.GoBack(); e.Handled = true; }
        var currentView = SystemNavigationManager.GetForCurrentView();
        currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

    }
    private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
    {

        if (cp.Layer.CanGoBack == true) {cp.Layer.GoBack(); e.Handled = true; }
        var currentView = SystemNavigationManager.GetForCurrentView();
        currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

    }

CP=ContentPage(主页)

我制作了一个简单的应用程序,可以显示导航

应用程序的主页是(让我们称之为rootpage):FramePage.xaml 还有其他3个xaml页面(我们称之为子页面):Frame1.xaml、Frame2.xaml、Frame3.xaml

因此,我的根页面中有一个框架,底部有一个命令栏,有两个按钮“后退”和“下一步”在框架中导航

因此,当我们单击“下一步”按钮时,它将如下所示

_FirstPage.Layer.Navigate(BlankPage2),this);
框架1->框架2->框架3

当您单击“后退”按钮时,它将检查帧是否可以返回。 如果可以,它将返回到上一帧

为了跟踪帧,我在每个帧中保留了一个文本块,显示帧名称

这是密码

对于FramePage.xaml

XAML

<Page.BottomAppBar>
    <CommandBar>
        <AppBarButton x:Name="back" HorizontalAlignment="Left" Icon="Back" Label="back" VerticalAlignment="Top" Click="back_Click"/>
        <AppBarButton x:Name="next" HorizontalAlignment="Left" Icon="Forward" Label="forward" VerticalAlignment="Top" Click="next_Click"/>
    </CommandBar>
</Page.BottomAppBar>


<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Frame x:Name="mainFrame">

    </Frame>
</Grid>
Frame1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>

Frame2.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>

Frame3.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>


希望这能有所帮助。

我制作了一个简单的应用程序,可以显示导航

应用程序的主页是(让我们称之为rootpage):FramePage.xaml 还有其他3个xaml页面(我们称之为子页面):Frame1.xaml、Frame2.xaml、Frame3.xaml

因此,我的根页面中有一个框架,底部有一个命令栏,有两个按钮“后退”和“下一步”在框架中导航

因此,当我们单击“下一步”按钮时,它将如下所示

_FirstPage.Layer.Navigate(BlankPage2),this);
框架1->框架2->框架3

当您单击“后退”按钮时,它将检查帧是否可以返回。 如果可以,它将返回到上一帧

为了跟踪帧,我在每个帧中保留了一个文本块,显示帧名称

这是密码

对于FramePage.xaml

XAML

<Page.BottomAppBar>
    <CommandBar>
        <AppBarButton x:Name="back" HorizontalAlignment="Left" Icon="Back" Label="back" VerticalAlignment="Top" Click="back_Click"/>
        <AppBarButton x:Name="next" HorizontalAlignment="Left" Icon="Forward" Label="forward" VerticalAlignment="Top" Click="next_Click"/>
    </CommandBar>
</Page.BottomAppBar>


<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Frame x:Name="mainFrame">

    </Frame>
</Grid>
Frame1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>

Frame2.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>

Frame3.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>


希望这能有所帮助。

您能否使用Window.Current.Frame作为Frame,然后找到Frame的名称。然后使用该名称决定导航位置?例如,如果当前Frame的名称为“BlankPage2”,则它应该导航到“BlankPage1”。由于帧数有限,您可以手动覆盖我已经尝试过的导航。不可能。问题似乎出在后台。您能否使用Window.Current.Frame作为Frame,然后找到Frame的名称。然后使用该名称决定导航位置?例如,如果当前帧的名称为“BlankPage2”然后它应该导航到“BlankPage1”。由于帧数有限,您可以手动覆盖导航。我已经尝试过了。没有机会。问题似乎出在后台。