Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding Issues on Xamarin forms #85

Open
mohammedmsadiq opened this issue Feb 3, 2020 · 2 comments
Open

Binding Issues on Xamarin forms #85

mohammedmsadiq opened this issue Feb 3, 2020 · 2 comments

Comments

@mohammedmsadiq
Copy link

mohammedmsadiq commented Feb 3, 2020

i cant get this to work through binding. but static number works, see below my implementation

(xaml file)
<local:Page1
Title="My Page"
x:Name="Item1"
plugin:TabBadge.BadgeText="{Binding Count}"
plugin:TabBadge.BadgeColor="Red"
plugin:TabBadge.BadgeTextColor="White" />

(ViewModel)
public override void OnAppearing()
{
var result = await this.notificationService.GetNotificationCount();
this.Count = result.Count;
base.OnAppearing();
}

    public string Count
    {
        get
        {
            return this.count;
        }
        set
        {
            this.SetProperty(ref this.count, value);
        }
    }
@mohammedmsadiq
Copy link
Author

i also tried the implementation on your sample project and property is not detected any changes. see below;

public class MasterTabbedPageViewModel : ViewModelBase, INotifyPropertyChanged
{
readonly INotificationService notificationService;

    public MasterTabbedPageViewModel(INavigationService navigationService, INotificationService notificationService, IPageDialogService pageDialogService, IProfilePictureService profilePictureService, IDeviceService deviceService, IEventAggregator eventAggregator, IAnalyticsService analyticsService) : base(navigationService, pageDialogService, profilePictureService, deviceService, eventAggregator, analyticsService)
    {
        Title = "MasterTabbedPage";
        this.notificationService = notificationService;           
    }

    public override void OnAppearing()
    {
        this.ExecuteAsyncTask(async () =>
        {
            var item = await this.notificationService.GetNotificationCount();
            courseCount = item.NewCourseCount;
            taskCount = item.TaskCount;
        });
        base.OnAppearing();
    }

    private int courseCount;

    public string CourseCount => courseCount <= 0 ? string.Empty : courseCount.ToString();

    public int CourseCountValue
    {
        get => courseCount;
        set
        {
            if (courseCount == value)
                return;

            courseCount = value;
            RaisePropertyChanged(nameof(CourseCountValue));
            RaisePropertyChanged(nameof(CourseCount));
        }
    }

    private int taskCount;

    public string TaskCount => taskCount <= 0 ? string.Empty : taskCount.ToString();

    public int TaskCountValue
    {
        get => taskCount;
        set
        {
            if (taskCount == value)
                return;

            taskCount = value;
            RaisePropertyChanged(nameof(TaskCountValue));
            RaisePropertyChanged(nameof(TaskCount));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void RaisePropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

}

@jmblargent
Copy link

If you are binding to the TabbedPage ViewModel, you need to specify the source and path for the binding. In your first example, if your TabbedPage is named Tabs, then the binding would look like {Binding Source={x:Reference Tabs}, Path=BindingContext.Count}. If you don't set the source, then it is looking for Count in the binding context of Page1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants