我正在使用此Plugin.Badge在 Xamarin Forms 应用程序的选项卡式视图中显示购物车项目计数。
这是我的标签页 xaml 代码MainPage.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:Projectname.Views" x:Class="Projectname.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= "{Binding Counter}"
plugin:TabBadge.BadgeColor="Red"
plugin:TabBadge.BadgeTextColor="White" plugin:TabBadge.BadgePosition="PositionTopRight" >
<x:Arguments>
<views:AboutPage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Account" IconImageSource="account.png">
<x:Arguments>
<views:AccountPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
下面是MainPage.xaml.cs中的代码
using System;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Essentials;
using Plugin.Badge.Abstractions;
using System.Collections.ObjectModel;
//using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace Projectname.Views
{
[DesignTimeVisible(false)]
public partial class MainPage : TabbedPage
{
int Counter;
public MainPage()
{
InitializeComponent();
Counter = 2;
}
}
}
在您可以看到的标签页子项之一中,徽章设置为 plugin:TabBadge.BadgeText= ""{Binding Counter}"
但不工作。
我想将徽章计数器的值设置为页面 MainPage.xaml.cs后面代码中的变量值
为此,要在代码中进行所有更改。请帮助我。