Xamarin 基础 ContentPage 加载(或常见的 ContentViews)

Xamarin base ContentPage with loading (or common ContentViews)

如何创建一个 "base" ContentPage,其中包含一个 busy indicator 示例,并使这个 Page 成为我应用程序中每个其他页面的基础?

我试过这样做,但是没有显示busy indicator

基页:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:core="clr-namespace:SgatMobileV3.Core;assembly=SgatMobileV3"
             x:Class="SgatMobileV3.Core.BasePage">
    <ContentPage.Content>
        <Grid>
            <core:VolosLoadingView />
        </Grid>
    </ContentPage.Content>
</ContentPage>

忙指示器视图:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:core="clr-namespace:SgatMobileV3.Core;assembly=SgatMobileV3"
             core:LocatorViewModel.AutoWireViewModel="true"
             x:Class="SgatMobileV3.Core.VolosLoadingView"
             xmlns:busyindicator="clr-namespace:Syncfusion.SfBusyIndicator.XForms;assembly=Syncfusion.SfBusyIndicator.XForms">

    <Grid>
     <Grid BackgroundColor="LightGray" Opacity="0.6" IsVisible="True" />
     <busyindicator:SfBusyIndicator
        IsBusy="True"
        IsVisible="True"
        x:Name="loading" AnimationType="DoubleCircle"
        ViewBoxWidth="150" ViewBoxHeight="150"
        TextColor="Green" BackgroundColor="Transparent"
        HorizontalOptions="Center" VerticalOptions="Center"/>       
     </Grid>
</ContentView>

一页:

<core:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:core="clr-namespace:SgatMobileV3.Core;assembly=SgatMobileV3"
             core:LocatorViewModel.AutoWireViewModel="true"
             x:Class="SgatMobileV3.Views.MockPage">

    <ContentPage.Content>
        <Grid>
            <Button Text="Welcome to Xamarin.Forms! 1"
                    VerticalOptions="CenterAndExpand" 
                    HorizontalOptions="CenterAndExpand"
                    Command="{Binding Test_ClickCommand}" />
        </Grid>
    </ContentPage.Content>
</core:BasePage>

我试图在 基本页面 中包含一个示例 label,但什么也没有出现。

您可以在代码中添加控件(在 BasePage.cs 文件中),我认为没有 XAML 解决方案。

how can I create a "base" ContentPage that contains, for sample, a busy indicator, and make this Page the base for each other pages

如果想在页面级别创建ControlTemplate,在应用级别创建ControlTemplate实例,也可以在页面级别创建,如following code example所示:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SimpleTheme.HomePage">
    <ContentPage.Resources>
        <ResourceDictionary>
            <ControlTemplate x:Key="TealTemplate">
                ...
            </ControlTemplate>
            <ControlTemplate x:Key="AquaTemplate">
                ...
            </ControlTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentView ... ControlTemplate="{StaticResource TealTemplate}">
        ...
    </ContentView>
</ContentPage>

在页面级别添加 ControlTemplate 时,ResourceDictionary 会添加到 ContentPage, and then theControlTemplate` 实例包含在 ResourceDictionary 中。

也可以用code , from doc has a sample举例。