0

我在一个包含 4 个选项卡的Xamarin.Forms.Shell 应用程序上工作。

在主选项卡上,我有:

  • aTitleView包含公司标志的
  • sScrollView包含一个Imageas Header
  • aScrollView包含主要内容,可以覆盖Header使其完全可见

XAML 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="AvilaShellAppSample.Views.HomePage"

            Shell.NavBarHasShadow="False"
            Shell.NavBarIsVisible="True"
            x:Name="homePage">
    <!-- TitleView -->
    <Shell.TitleView >
        <Grid>
            <ffimageloadingsvg:SvgCachedImage Source="resource://ShellAppSample.Resources.blackLogoTitle.svg"
                                            DownsampleHeight="6"
                                            HeightRequest="45"/>
        </Grid>
    </Shell.TitleView>
    <ContentPage.BindingContext>
        <vm:HomeViewModel />
    </ContentPage.BindingContext>
    <ContentPage.Content>
        <Grid RowSpacing="0"
            BackgroundColor="{StaticResource Gray-050}"
            Margin="0,0,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="1">
                <!--  Header ScrollView : Image  -->
                <ScrollView>
                    <ContentView x:Name="headerView"
                                HorizontalOptions="FillAndExpand"
                                VerticalOptions="FillAndExpand">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <!--  Header Image  -->
                            <ffimageloading:CachedImage x:Name="headerImage"
                                            Grid.Row="0"
                                            Aspect="AspectFill"
                                            BackgroundColor="{DynamicResource Gray-200}"
                                            DownsampleToViewSize="true"
                                            HeightRequest="280"
                                            HorizontalOptions="FillAndExpand"
                                            VerticalOptions="Start"
                                            Source="resource://ShellAppSample.Resources.indoor.jpg">
                            </ffimageloading:CachedImage>
                        </Grid>
                    </ContentView>
                </ScrollView>

                <!--  Content ScrollView  -->
                <ScrollView>
                <ctrl:ParallaxScrollView HorizontalOptions="FillAndExpand"
                                        VerticalOptions="FillAndExpand"
                                        ParallaxHeaderView="{x:Reference headerView}"
                                        LogoHeaderView="{x:Reference logoHeaderView}"
                                        HiddenView="{x:Reference hiddenView}"
                                        MainPage="{Binding homePage}">
                    <Grid ColumnSpacing="0"
                        RowSpacing="0"
                        VerticalOptions="FillAndExpand">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="220" /> 
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <!-- Content -->
                    </Grid>
                </ctrl:ParallaxScrollView>
                </ScrollView>
            </Grid>
        </Grid>
    </ContentPage.Content>
</ContentPage>

默认情况下,我想在/上显示标题 :因此将隐藏,背景将是标题。然后我想仅在内容覆盖Header的一半时显示默认/ :这样才会可见,并且背景将是默认背景。ImageNavigationBarStatusBarNavigationBarStatusBarImage NavigationBarStatusBarNavigationBarStatusBar

但是我没有找到任何访问该Shell.NavBarIsVisible属性或Shell.TitleView代码隐藏的方法。

所以我想知道这可能吗?

4

1 回答 1

1

您需要使用公开的方法来设置属性SetNavBarIsVisible()SetTitleView()

在代码隐藏中禁用页面的导航栏:

Shell.SetNavBarIsVisible(this, false);

TitleView在代码隐藏中为页面设置自定义:

Label r = new Label();
r.Text = "Hello World";
Shell.SetTitleView(this, (View)r);
于 2020-11-15T13:35:48.683 回答