我有个问题。我创建了一个自定义TitleBar,如下所示:
<Shell.TitleView>
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="Fill">
<Image Source="Title_Dark.png" HorizontalOptions="CenterAndExpand" HeightRequest="25" Margin="0, 0, 20, 0" />
<Image Source="Add.png" HorizontalOptions="End" HeightRequest="35" Margin="0, 0, 8, 0">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="imgAdd_Clicked" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</Shell.TitleView>当我点击TitleBar中的图像"Add“时,我会转到这样的TabbedPage:
TabbedPage page = new TabbedPage();
page.Children.Add(new MemeBuilder());
page.Children.Add(new MemeTemplateList());
await Navigation.PushAsync(page);现在,我想保留第一个页面中的TitleBar,并使用该栏下面的选项卡页栏。这是可能的吗?如何实现?
发布于 2019-12-11 05:30:03
您可以使用ControlTemplate来做到这一点
在App.xaml中定义ControlTemplate
<ControlTemplate x:Key="TopBar">
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="Fill">
<Image Source="Title_Dark.png" HorizontalOptions="CenterAndExpand" HeightRequest="25" Margin="0, 0, 20, 0" />
<Image Source="Add.png" HorizontalOptions="End" HeightRequest="35" Margin="0, 0, 8, 0">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{TemplateBinding Parent.BindinContext.Command1}" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</ControlTemplate>在任何使用外壳的ContentPage上
Shell.TitleView = new TemplatedView(Application.Current.Resources["TopBar"]);<ContentPage>
<Shell.TitleView>
<TemplatedView ControlTemplate={StaticResource TopBar} />
</Shell.TitleView>
</ContentPage>在使用默认NavigationPage的ContentPages上
<NavigationPage.TitleView>
<TemplatedView ControlTemplate={StaticResource TopBar}/>
</NavigationPage.TitleView>https://stackoverflow.com/questions/59221608
复制相似问题