【发布时间】:2022-09-27 17:03:12
【问题描述】:
使用基于 Xamarin.Forms Shell uri 的导航显示模式页面的“新”和推荐方法是在 XAML 文件 (source) 中设置此标记:Shell.PresentationMode=\"ModalAnimated\"
并通过使用标准路线并使用函数Shell.Current.GoToAsync(\"routeToMyPage\") 调用它来导航到它。
但是,这将显示没有工具栏的模式页面。如果没有 Shell 导航,我会将此页面包装在 NavigationPage 中,但由于页面是通过反射初始化的(至少它看起来是这样的 - 不要引用我的话),我不会不知道该怎么做。
在页面的 XAML 代码中添加 ToolbarItem 并不能解决此问题,Shell.NavBarIsVisible=\"True\" 属性也不能解决此问题,并且在 Shell.TitleView 标记中添加 Button 也不会显示工具栏。
有没有一种方法可以显示默认导航工具栏而无需自己渲染自定义工具栏?
这是我用来尝试显示工具栏的 XAML 代码:
<ContentPage
xmlns=\"http://xamarin.com/schemas/2014/forms\"
xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\"
Shell.PresentationMode=\"ModalAnimated\"
Shell.NavBarIsVisible=\"True\"
x:Class=\"StackOverflow.Views.MyModalPage\">
<ContentPage.ToolbarItems >
<ToolbarItem Text=\"Hi\"/>
</ContentPage.ToolbarItems>
<Shell.TitleView>
<Button Text=\"Toolbar Button\"/>
</Shell.TitleView>
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
编辑:我创建了一个小示例项目来展示我的问题:https://github.com/Kuurse/StackOverflowExample
标签: c# xaml xamarin.forms