【问题标题】:Badge counter in Xamarin Forms not workingXamarin Forms 中的徽章计数器不起作用
【发布时间】:2020-08-02 00:54:33
【问题描述】:

我正在使用此 Plugin 在 Xamarin Forms 应用程序的选项卡式视图中显示徽章计数。

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"
            xmlns:d="http://xamarin.com/schemas/2014/forms/design"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
            xmlns:plugin="clr-namespace:Plugin.Badge.Abstractions;assembly=Plugin.Badge.Abstractions"
            xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" android:TabbedPage.ToolbarPlacement="Bottom"
            SelectedTabColor="{StaticResource HighlightText}"  BarBackgroundColor="{StaticResource HighlightBg}" UnselectedTabColor="Gray" 
            xmlns:views="clr-namespace:Sello.Views" x:Class="Sello.Views.MainPage" >
   <TabbedPage.Children>
        <NavigationPage Title="Home" IconImageSource="home.png">
                  <x:Arguments>
                <views:HomePage />
            </x:Arguments>
        </NavigationPage>

         <NavigationPage Title="Search" IconImageSource="search.png">
            
            <x:Arguments>
                <views:AboutPage />
            </x:Arguments>
        </NavigationPage>

         <NavigationPage Title="Cart" IconImageSource="cart.png"
             plugin:TabBadge.BadgeText= "2" 
             plugin:TabBadge.BadgeColor="Red"
              plugin:TabBadge.BadgeTextColor="White"   plugin:TabBadge.BadgePosition="PositionCenter"       >
            
            <x:Arguments>
                <views:AboutPage />
            </x:Arguments>
        </NavigationPage>


        <NavigationPage Title="Account" IconImageSource="account.png">
            
            <x:Arguments>
                <views:AccountPage />
            </x:Arguments>
        </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>

也如plugin doucmentation 中所述 在 AssemblyInfo.cs 中添加了以下行

[assembly: ExportRenderer(typeof(TabbedPage), typeof(BadgedTabbedPageRenderer))]

添加此行时,显示以下错误消息

找不到类型或命名空间名称“ExportRenderer”(是 您缺少 using 指令或程序集引用?)

所以当我评论上述行时,应用程序运行时没有错误,但没有显示徽章。对于测试,我尝试在另一个测试应用程序上实现相同的功能,但也无法正常工作。 请帮我解决这个问题。

【问题讨论】:

    标签: xaml xamarin.forms badge


    【解决方案1】:

    找不到类型或命名空间名称“ExportRenderer”(是 您缺少 using 指令或程序集引用?)

    正如错误告诉您的那样,您缺少 using 指令。添加这个(为Android项目将iOS更改为Android)

    using Plugin.Badge.iOS;
    

    您还需要确保在平台项目(iOS、Android 等)中执行此操作,而不是在共享表单项目中

    查看sample project 示例

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 2020-03-17
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多