【发布时间】:2020-08-04 11:44:28
【问题描述】:
我正在使用此 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= ""{绑定计数器}"
但不起作用。
我想将徽章计数器的值设置为页面后面代码中变量的值MainPage.xaml.cs
为此,要在代码中进行所有更改。请帮我解决这个问题。
【问题讨论】:
-
您好,您需要在子页面中绑定值,而不仅仅是在
MainPage中。你可以看看sample code。我不知道为什么这在 MainPage 中不起作用,也许这是这个 NugetPackage 的问题。
标签: xaml xamarin xamarin.forms xamarin-forms-4