xaml - Xamarin.Forms:是否可以在代码隐藏中更新 Shell.TitleView?
问题描述
我在一个包含 4 个选项卡的Xamarin.Forms.Shell 应用程序上工作。
在主选项卡上,我有:
- a
TitleView
包含公司标志的 - s
ScrollView
包含一个Image
as Header - a
ScrollView
包含主要内容,可以覆盖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的一半时显示默认/ :这样才会可见,并且背景将是默认背景。Image
NavigationBar
StatusBar
NavigationBar
StatusBar
Image
NavigationBar
StatusBar
NavigationBar
StatusBar
但是我没有找到任何访问该Shell.NavBarIsVisible
属性或Shell.TitleView
代码隐藏的方法。
所以我想知道这可能吗?
解决方案
您需要使用公开的方法来设置属性SetNavBarIsVisible()和SetTitleView()
在代码隐藏中禁用页面的导航栏:
Shell.SetNavBarIsVisible(this, false);
TitleView
在代码隐藏中为页面设置自定义:
Label r = new Label();
r.Text = "Hello World";
Shell.SetTitleView(this, (View)r);
推荐阅读
- python - 模块无法与 pygame 一起正常工作
- django - 如何在 Django 1.11 中使用从查询集 TruncYear 生成的对象关系序列化列表
- javascript - 使用 ngIf 错误时如何禁用 Angular 6 中的按钮保存
- c - strcpy 到 struct 时出现分段错误
- mongodb - 通过终端设置 MongoDB 的 DB 路径
- python - 对于 Numpy 数组中的所有元素,在另一个数组中返回它们的索引
- javascript - 通过在 Textarea 上拖放加载文本文件
- python - 将参数从字典传递给类
- flutter - 升级颤振后颤振标签栏错误“getter'key'被称为null”
- angular - Angular Material Datepicker - 仅限月份和年份