【问题标题】:Xamarin.Forms: Tabs with Sharnado.presentation.forms do not respond to tapXamarin.Forms:带有 Sharnado.presentation.forms 的选项卡不响应点击
【发布时间】:2019-10-27 00:51:56
【问题描述】:

我正在尝试使用Sharpnado's awesome tab 功能来创建他们所谓的“固定标签”。但它并没有按照我的意愿做 - 问题可能出在其他地方......基本上,选项卡没有响应点击。通过这个简单的示例,我将其范围缩小到了这一点。

上下文是一个使用普通标签页的应用程序(每个标签页都有导航页)。在其中一个选项卡上,我尝试放置 TabHostViewcontrol - 即使没有绑定,因为我最初认为这是问题所在。这是测试页面的截图: 当我点击两个选项卡(“Personlig”和“Udforsk”)时,什么也没有发生。 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"
        xmlns:tabs="clr-namespace:Sharpnado.Presentation.Forms.CustomViews.Tabs;assembly=Sharpnado.Presentation.Forms"
        xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
        ios:Page.UseSafeArea="true"
        xmlns:views="clr-namespace:Angler.Views.Partials"
        x:Class="Angler.Views.StatisticsPage">
    <NavigationPage.TitleView>
        <Label Text="{Binding Title}" HorizontalOptions="Center"
                VerticalOptions="Center" Style="{StaticResource PageTitle}" />
    </NavigationPage.TitleView>
    <StackLayout VerticalOptions="FillAndExpand" BackgroundColor="LightYellow">
        <Label Text="{Binding ShowSelectedTab}" Margin="20,10" />
        <Grid RowSpacing="0" ColumnSpacing="0" Margin="0"
                BackgroundColor="LightPink" VerticalOptions="FillAndExpand">
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <tabs:TabHostView ShadowType="Bottom" Grid.Row="0">
                <tabs:TabHostView.Tabs>
                    <tabs:UnderlinedTabItem Label="Personlig" />
                    <tabs:UnderlinedTabItem Label="Udforsk" IsSelected="True" />
                </tabs:TabHostView.Tabs>
            </tabs:TabHostView>
        </Grid>
    </StackLayout>
</ContentPage>

viewmodel 看起来像这样(尽管上面已经缩小到不使用 tabindex 的属性。但我也调查了 viewmodel 的绑定上下文是否正常 - 似乎是这样):

public class StatisticsPageViewModel : ViewModelBase
{
    public int SelectedTabIndex { get; set; }
    public string ShowSelectedTab { get { return $"Index: {SelectedTabIndex}"; } }
    public StatisticsPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService,
        IDeviceService deviceService) : base(navigationService, pageDialogService,
            deviceService)
    {
        Title = AppResources.StatisticsPageTitle;
    }

    public override void OnAppearing()
    {
        //SelectedTabIndex = 1;
        base.OnAppearing();
        Analytics.TrackEvent("Navigate to Statistics");
    }
}

我正在使用 VisualStudio for Mac 8.3.4(内部版本 8)、Sharpnado.presentations.forms 1.3.0 和 Prism.forms 7.2.0.1367。

我已尝试将 InputTransparent="True" 添加到某些容器对象 - 没有效果。

任何关于如何解决这个问题的好主意都非常感谢!

【问题讨论】:

    标签: xamarin.forms tabs


    【解决方案1】:

    好吧,这只是愚蠢的(浪费了两天!)...

    在尝试解决其他问题时,我已经退回到我的源代码库 - 并且曾经退回得太远......所以平台项目中 Sharpnado 的初始化不存在。那是有区别的。

    因此,如果您不记得将这一行添加到您的平台项目中,您会看到这种行为:

    SharpnadoInitializer.Initialize()
    

    把它留在这里以防其他人可能会出现相同的症状:-)

    【讨论】:

    • 嗯,我想我需要以更好的方式强调这一点:)
    • 是的,@JackHua-MSFT - 但是在发布您自己的答案的解决方案后必须等待 2-3 天,然后才能将其标记为答案 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多