【发布时间】:2022-06-16 07:48:14
【问题描述】:
所以我只是在试验 .NET MAUI/Blazor Hybrid。
我已按照 .NET MAUI 指南设置我的 TabBar,结果如下所示:
但是,我需要将每个选项卡链接到剃须刀页面,因此 ContentTemplate="{DataTemplate local:Home}" 例如不起作用。
有人知道我如何将每个标签链接到剃须刀页面吗?
【问题讨论】:
标签: .net blazor maui maui-blazor
所以我只是在试验 .NET MAUI/Blazor Hybrid。
我已按照 .NET MAUI 指南设置我的 TabBar,结果如下所示:
但是,我需要将每个选项卡链接到剃须刀页面,因此 ContentTemplate="{DataTemplate local:Home}" 例如不起作用。
有人知道我如何将每个标签链接到剃须刀页面吗?
【问题讨论】:
标签: .net blazor maui maui-blazor
在这些数据模板中的每一个中,您都需要一个模板,该模板有一个 BlazorWebView 指向您要显示的页面。写在一个文件中。看起来像这样,当然您可以将每个模板放在不同的文件中:
<Application.MainPage>
<Shell>
<TabBar>
<Tab Title="Home">
<ShellContent Title="Home">
<ShellContent.ContentTemplate>
<DataTemplate>
<ContentPage>
<BlazorWebView HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type pages:Index}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</ContentPage>
</DataTemplate>
</ShellContent.ContentTemplate>
</ShellContent>
</Tab>
<Tab Title="Log">
<ShellContent Title="Log">
<ShellContent.ContentTemplate>
<DataTemplate>
<ContentPage>
<BlazorWebView HostPage="wwwroot/index.html">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type pages:Counter}" />
</BlazorWebView.RootComponents>
</BlazorWebView>
</ContentPage>
</DataTemplate>
</ShellContent.ContentTemplate>
</ShellContent>
</Tab>
</TabBar>
</Shell>
</Application.MainPage>
注意:
xmlns:pages="clr-namespace:YourProjectName.Pages" 命名空间声明BlazorWebView 指向命名空间中的 (Blazor) 页面之一 about在此处查找完整的工作示例:https://github.com/jfversluis/MauiBlazorPlatformTabs
【讨论】:
1-创建文件夹名称Pages并将所有页面放入其中, 2- 添加 ( xmlns:Page="clr-namespace:Market.Pages") Market 是您的项目名称, 3-在标签添加()“DetailsPage”这里是你的导航页enter image description here
【讨论】: