Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.

[Bug] The initial value of property couldn't display correctly on xct:BadgeView when using data binding. #1900

@jessiezh0320

Description

@jessiezh0320

Description

The initial value of the binding property couldn't display correctly on xct:BadgeView when using data binding. But after changing the value of the binding property, the UI could update correctly on xct:BadgeView.

Stack Trace

Link to Reproduction Sample

Steps to Reproduce

  1. create a xamarin forms demo
  2. copy the following code to this demo:
 public class MyViewModel: INotifyPropertyChanged { public ICommand TestCommmand => new Command(TestMethod); private void TestMethod(object obj) { NotificationsNumber = 168; } private int _notificationsNumber = 0; public int NotificationsNumber { get => _notificationsNumber; set => SetProperty(ref _notificationsNumber, value); } public MyViewModel() { NotificationsNumber = 0; } bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null) { if (Object.Equals(storage, value)) return false; storage = value; OnPropertyChanged(propertyName); return true; } protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public event PropertyChangedEventHandler PropertyChanged; } 

MainPage.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:xct="http://xamarin.com/schemas/2020/toolkit" xmlns:formapp826="clr-namespace:FormApp826" x:Class="FormApp826.MainPage"> <ContentPage.BindingContext> <formapp826:MyViewModel></formapp826:MyViewModel> </ContentPage.BindingContext> <StackLayout Padding="10"> <Label Text="{Binding NotificationsNumber}" HorizontalOptions="Center" FontSize="Header" /> <xct:BadgeView Margin="10" BackgroundColor="Red" FontAttributes="Bold" FontSize="Medium" TextColor="White" Text="{Binding NotificationsNumber}"> <Label Text="This label has a badge in the top-right"/> </xct:BadgeView> <Button Text="change value" Command="{Binding TestCommmand}" /> </StackLayout> </ContentPage> 
  1. deploy the app to a android device, the result is as follows:

image

We could find that the first Label could display NotificationsNumber correctly(0) ,but for the xct:BadgeView ,the value of NotificationsNumber can not display correctly.

After that, we can try to click button change value, here we change the value of NotificationsNumber, we can find that the value of NotificationsNumber could update correctly for both label and xct:BadgeView .

image

Expected Behavior

The initial value of property could display correctly on xct:BadgeView when using data binding.

Actual Behavior

The initial value of property couldn't display correctly on xct:BadgeView when using data binding.

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Workaround

Reproduction imagery

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Breaky break.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions