【问题标题】:How to load a content page(xaml) to another page(xaml) in xamarin.Forms , but keep the header and footer same (like tab in Xamarin.Android)如何将内容页面(xaml)加载到 xamarin.Forms 中的另一个页面(xaml),但保持页眉和页脚相同(如 Xamarin.Android 中的选项卡)
【发布时间】:2019-05-10 04:18:44
【问题描述】:

我希望在 Xamarin.Forms 中创建一个自定义选项卡式页面,其中页眉和页脚保持不变。中间部分包含内容。

标题通常是文本标题。只有屏幕的中心部分会根据选项卡的选择不断变化。

页脚包含不同的选项卡。它也不像通常的标签页。它更像是一个 Button,在被选中时会改变颜色,并且它们之间有一定的间隙。

这是一个示例图片

【问题讨论】:

  • 您可以在内容页面中使用内容视图。
  • @PragneshMistry 在 xmarin.Forms 中查看?
  • 是 ContentView,我在内容页面中使用了内容视图

标签: xamarin.forms


【解决方案1】:

您可以通过右键单击项目,按“添加”然后添加 ContentView 来创建 ContentView。

然后您可以使用网格并创建不同的行,并在一行上引用 ContentView,在另外两行上引用页眉和页脚。

Xaml 的顶部引用这样的 ContentView。

xmlns:Views="clr-namespace:SharedTestProject.ContentViews"

然后像这样定义Xaml 的其余部分。之后您所要做的就是实现逻辑以更改可见视图。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="55"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid x:Name="NavigationButtons" HeightRequest="55" Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="140"/>
            <ColumnDefinition Width="140"/>
            <ColumnDefinition Width="140"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" HeightRequest="50" WidthRequest="140" VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand">
            <Button x:Name="BtnView1" Clicked="BtnView1_Clicked" Text="View1"/>
        </Grid>
        <Grid Grid.Column="1" HeightRequest="50" WidthRequest="140" VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand">
            <Button x:Name="BtnView2" Clicked="BtnView2_Clicked" Text="View2"/>
        </Grid>
        <Grid Grid.Column="2" HeightRequest="50" WidthRequest="140" VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand">
            <Button x:Name="BtnView3" Clicked="BtnView3_Clicked" Text="View3"/>
        </Grid>
    </Grid>

    <Grid x:Name="ContentViews" Grid.Row="1">
        <ContentViews:View1 x:Name="View1" IsVisible="True"/>
        <ContentViews:View2 x:Name="View2" IsVisible="False"/>
        <ContentViews:View3 x:Name="View3" IsVisible="False"/>
    </Grid>
</Grid>

【讨论】:

  • 这会像我们通常在 OnAppearing 中那样加载数据吗?动画呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-14
  • 1970-01-01
相关资源
最近更新 更多