【问题标题】:Xamarin use TitleBar and TabbedPage BarXamarin 使用 TitleBar 和 TabbedPage Bar
【发布时间】:2019-12-11 05:30:03
【问题描述】:

我有一个问题。我创建了一个这样的自定义 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 中的图片“添加”时,我会转到一个 TabbedPage,如下所示:

TabbedPage page = new TabbedPage();
page.Children.Add(new MemeBuilder());
page.Children.Add(new MemeTemplateList());

await Navigation.PushAsync(page);

现在我想保留首页的 TitleBar 并使用该栏下方的标签页栏。这可能吗?如何实现?

【问题讨论】:

  • 不,当你推送到一个新页面时,导航栏是新页面的一个新的。您可以在新页面中创建相同的 TitleView,使其看起来相同。

标签: c# xamarin xamarin.forms xamarin.android xamarin.ios


【解决方案1】:

您可以使用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>

在任何使用 Shell 的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>

【讨论】:

    猜你喜欢
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 2020-12-15
    相关资源
    最近更新 更多