连接Xamarin表标签页,以XAML

问题描述 投票:0回答:1

我是相当新的这一切,我目前试图获得在Xamarin标签页形式的标签的高度。我发现这个问题唯一的解决办法是写一个自定义渲染,那就是我有一个困难时期的东西。

经过奋力的一两天,我设法去这个地方(希望在正确的轨道),但我只是不明白如何将XAML连接到我的自定义选项卡页面。这是我到目前为止所。

GameTab.xaml

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage 
            xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="Diplomacy.Views.GameTab"
            xmlns:pages="clr-namespace:Diplomacy.Views"
            xmlns:custom="clr-namespace:Diplomacy.CustomRenderers">
    <!--Pages can be added as references or inline-->

    <TabbedPage.Children>
        <pages:TabbedMap            Title="Map"         Icon="tank.png"/>
        <pages:TabbedChat           Title="Chat"        Icon="chat.png"/>
    </TabbedPage.Children>
</TabbedPage>

GameTab.xaml.cs

namespace Diplomacy.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class GameTab : Xamarin.Forms.TabbedPage
    {
        SelectionGamesViewModel viewModel;

        public GameTab(SelectionGamesViewModel viewModel)
        {
            InitializeComponent();

            // Disables switching between tabs with the swipe gesture
            On<Xamarin.Forms.PlatformConfiguration.Android>().DisableSwipePaging();

            // Sets the tab at the bottom in android phones
            On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);

            BindingContext = this.viewModel = viewModel;
        }
    }

MyCustomRenderer.cs

namespace Diplomacy.CustomRenderers
{
    public class CustomTabbedPage : Xamarin.Forms.TabbedPage
    {
    }
}

在这一点上我的下一个步骤是使用CustomTabbedPage(纠正我,如果我错了,从这里开始了)。

有了这条线:xmlns:custom="clr-namespace:Diplomacy.CustomRenderers"我应该能够对自己挤进我的定制渲染,目前什么也不做Xamarin标签页的形式。

我相信这样做的方法是通过改变TabbedPageCustomTabbedPage如下图所示

<?xml version="1.0" encoding="utf-8" ?>
<custom:CustomTabbedPage 
            xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="Diplomacy.Views.GameTab"
            xmlns:pages="clr-namespace:Diplomacy.Views"
            xmlns:custom="clr-namespace:Diplomacy.CustomRenderers">
    <!--Pages can be added as references or inline-->
.
. // Same stuff goes here
.

</custom:CustomTabbedPage>

然而,当我这样做,我得到的所有类型的错误在GameTab.xaml.cs和1级的错误。试图推GameTab(第2误差)的导航页

enter image description here

我一直在挣扎大概几个星期,我真的需要就如何建立这一习俗呈现一定的帮助。我得到它做什么理论,什么是它的目的,但我不完全了解编译器如何处理这一切,以及如何将其全部连接在一起。谢谢,麻烦您了。很抱歉的长期问题,我只是想彻底。

编辑:这是Android定制的渲染代码,住在Diplomacy.Android

[assembly: ExportRenderer(typeof(CustomTabbedPage), typeof(MyTabbedPage))]
namespace Diplomacy.Droid.CustomRenderer
{
    public class MyTabbedPage : TabbedRenderer
    {
        public MyTabbedPage(Context context) : base(context)
        {
        }
    }
}
xaml xamarin xamarin.forms custom-renderer tabbedpage
1个回答
0
投票

所有你得到的错误是一个独自一个原因,你的部分类即GameTab.xaml.cs文件GameTab类的其他部分并没有从您CustomTabbedPage但你Xamarin.Forms.TabbedPage继承

所有你需要做的就是在你的GameTab.xaml.cs这样的事情

   public partial class GameTab : Diplomacy.CustomRenderers.CustomTabbedPage
© www.soinside.com 2019 - 2024. All rights reserved.