首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin.Forms:在代码隐藏中可以更新Shell.TitleView吗?

Xamarin.Forms:在代码隐藏中可以更新Shell.TitleView吗?
EN

Stack Overflow用户
提问于 2020-11-15 11:20:58
回答 1查看 1.1K关注 0票数 0

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

在主标签上,我有:

  • 包含公司徽标的TitleView
  • S ScrollView包含Image作为标头
  • 包含ScrollView主内容的,它可以覆盖头以使其完全可见。

XAML如下所示:

代码语言:javascript
复制
<?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>

默认情况下,我想在/StatusBar上显示Image头,因此NavigationBar将是隐藏的,StatusBar的背景将是Image E 131头<代码>E 232。然后,我想显示默认的 NavigationBar/StatusBar,只有当内容覆盖头的一半时:因此NavigationBar将是可见,而StatusBar背景将是默认背景。

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

所以我想知道这是可能的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-15 13:35:48

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

取消其代码隐藏页的导航栏:

代码语言:javascript
复制
Shell.SetNavBarIsVisible(this, false);

为其代码隐藏中的页面设置自定义TitleView

代码语言:javascript
复制
Label r = new Label();
r.Text = "Hello World";
Shell.SetTitleView(this, (View)r);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64843774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档