简体   繁体   English

为什么我的模态页面有后退按钮?

[英]Why does my modal page have a back button?

Project and problem explanation 项目和问题解释

In my case I have a page which instructs the user how to move a certain machine. 在我的情况下,我有一个页面,指示用户如何移动某台机器。 This page is supposed to be a modal page since the page should not be navigated away from without performing or completely canceling the action. 此页面应该是模态页面,因为在不执行或完全取消操作的情况下不应导航页面。

在此输入图像描述 I have a mainpage with a listview which opens the details page of any of the items contained in the listview on click through the onSelect method: 我有一个带有列表视图的主页,通过点击onSelect方法打开列表视图中包含的任何项目的详细信息页面:

Navigation.PushAsync(new FooPage(string Name)); /* gets called in the 
onSelect method if selection is not null*/

The model is retrieved within the details page's viewmodel after passing the name to it and then using a model manager injected into the viewmodel with Unity to retrieve it. 在将名称传递给详细信息页面的viewmodel之后,在模型中检索该模型,然后使用注入到viewmodel中的模型管理器来检索它。

-- we now both have a mainpage and detailspage on the stack which of only the detailspage has a backbutton -- - 我们现在都在堆栈上有一个主页和详细信息页面,其中只有详细信息页面有一个后退按钮 -

On the detailspage we have a button called "Teach" with ax,y,z field next to it after clicking it this method gets called: 在详细信息页面上,我们有一个名为“Teach”的按钮,在单击它之后旁边有ax,y,z字段,此方法被调用:

private async Task Button_Clicked(object sender, EventArgs e)
        {
            await Navigation.PushModalAsync(new ManualTeachPage());
        }

which then, as it should, creates the page but then for some reason decides to add a back button to it: 然后,它应该创建页面,但由于某种原因决定添加一个后退按钮: Uwp后退按钮是可见的

Debugging and Research 调试和研究

This behavior is not visible on Android which does not have a visible back button or navigation bar on this page but does have a backbutton on the Details -page as well. 此行为在Android上不可见,此页面上没有可见的后退按钮或导航栏,但在详细信息页面上也有后退按钮。

I have used modal pages before but I have never seen this kind of behavior, I have tried using the Navigation property of the Application.Mainpage itself which resulted in the exact same result except for one case. 我之前使用过模态页面,但我从未见过这种行为,我尝试过使用Application.Mainpage本身的Navigation属性,除了一个案例外,结果完全相同。

I thought it might have something to do with me switching out the Application.Mainpage at one point(there is a stack of tutorial pages the user has to go through), seems like calling the pushModalAsync one line AFTER setting the new mainpage then it DOES push the page as a modal page and performs like one (without a back button) but does not do so after this point. 我认为这可能与我在某一点切换Application.Mainpage有关(用户必须经过一堆教程页面),似乎在设置新主页之后调用pushModalAsync一行然后它就行了将页面作为模态页面推送并执行一个(没有后退按钮)但在此之后不执行此操作。

No bug reports on Bugzilla about this either as far as I have seen, neither have I found anything on the internet about this particular problem. 就我所见,没有关于Bugzilla的错误报告,我没有在互联网上找到关于这个特定问题的任何内容。

Note that when clicking the back button on the teachPage it returns to the detailspage. 请注意,单击教学页面上的后退按钮时,它将返回到详细信息页面。 When the teachPage gets pushed it does actually get pushed onto the ModalStack. 当teachPage被推送时,它实际上被推送到ModalStack。

update 1 更新1

Checked again if the modal page which I was talking about was the only modal page on the modal Stack, it was. 再次检查我所谈论的模态页面是模态堆栈上唯一的模态页面,它是。 NavigationPage.SetHasBackButton(this, false); NavigationPage.SetHasBackButton(this,false); does not seem to work either as suggested by Diego Rafael Souza. 似乎没有按照Diego Rafael Souza的建议工作。

update 2 更新2

I thought I would temporarily disable the backbutton by using the onBackButtonPressed within the teachpage until I had found a solution. 我想我会在教学页面中使用onBackButtonPressed暂时禁用后退按钮,直到找到解决方案。 Turns out this doesn't work for UWP anymore, this method does not get called anymore on this page or any page for that matter. 事实证明这不再适用于UWP,此方法不再在此页面或任何页面上调用此方法。 It does work for the Android Hardware button though. 它虽然适用于Android硬件按钮。

update 3 更新3

I tried using: 我试过用:

SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = 
AppViewBackButtonVisibility.Collapsed;

This does hide the backbutton on UWP but for some reason #if WINDOWS_UWP doesn't work at all. 这确实隐藏了UWP上的后退按钮但由于某种原因#if WINDOWS_UWP根本不起作用。 If I do this without the #if the program won't build for Android. 如果我在没有#if的情况下执行此操作,程序将无法为Android构建。 No solution yet, not only this but when using this fix the other pages still had the onBackButtonPressed method disabled. 还没有解决方案,不仅如此,但在使用此修复程序时,其他页面仍然禁用了onBackButtonPressed方法。

update 4 更新4

after updating to the newest version of xamarin forms the OnBackButtonPressed started working again. 在更新到最新版本的xamarin表单后,OnBackButtonPressed再次开始工作。 The backbutton still appears on the page but I now have disabled it. 后退按钮仍然显示在页面上,但我现在已禁用它。

Recreating the problem 重新创造问题

I recreated the problem in this small test project: https://www.dropbox.com/sh/6btsud3uvw503ee/AAAiaGb3TwhMrZMJb2j-rd36a?dl=0 我在这个小测试项目中重新创建了这个问题: https//www.dropbox.com/sh/6btsud3uvw503ee/AAAiaGb3TwhMrZMJb2j-rd36a?dl = 0

In your function Button_Clicked() in your example, in page DetailPage , where you call your Modal, right after calling PushModalAsync(new TeachPage()); 在您的示例中的Button_Clicked()函数中,在调用Modal的页面DetailPage ,在调用PushModalAsync(new TeachPage()); , use: , 采用:

NavigationPage.SetHasNavigationBar(this, false);
NavigationPage.SetHasBackButton(this, false);

My guess is when you tried using the above SetHasBackButton , you were doing it on the Modal itself, but the back button you were actually seeing came from your DetailPage. 我的猜测是当你尝试使用上面的SetHasBackButton ,你是在Modal本身上做的,但你实际看到的后退按钮来自你的DetailPage。

Once you add this, the modal pops up, and the back button disappears. 添加此项后,模式会弹出,后退按钮会消失。 If you set a "Back" button on your modal in order to close it, you can easily get your NavBar and BackButton back in your DetailPage by adding in an OnAppearing() Function in your DetailPage code-behind like so: 如果在模态上设置“后退”按钮以关闭它,则可以通过在DetailPage代码隐藏中添加OnAppearing()函数轻松地将NavBar和BackButton返回到DetailPage中:

protected override void OnAppearing()
{
    base.OnAppearing(); // do the usual stuff OnAppearing does
    NavigationPage.SetHasNavigationBar(this, true); //get your navbar back
    NavigationPage.SetHasBackButton(this, true); //get your back button back
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 继承后,为什么我的Timer返回null? - Why does my Timer come back null when I have inherited it? 为什么我的模态表单将空模型发布回控制器 - Why is my Modal form posting a null model back to the controller 为什么我的链接按钮会执行完整的回发,尽管它是由更新面板触发的 - Why my link button does a full post back although it 's triggered with an update panel 为什么我的Umbraco根页面仅在当前活动页面时没有子级? - Why does my root Umbraco page have no Children only when it is the currently active page? 当单击视图中的过滤器按钮时,为什么页面会刷新? - Why does my page refresh when I click the filter button in my view? 如何停止显示我已离开页面的浏览器后退按钮 - How to stop browser back button showing a page I have left 访问模式页面上的按钮 - Access a button on modal page 为什么按钮的内容模板没有对象? - why content template of button does not have object? 转发器按钮发回到page_load而不是我的方法? - Repeater button posting back to page_load instead of my method? 带框架的Splitview并导航到另一页,后退按钮不起作用 - Splitview with frame and navigating to another page, back button does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM