This is my string:
public string EmptyViewText { get; set; } = "Please input a bin id first!*";
I have a simple command:
public async Task Entry(string barcode)
{
MainThread.BeginInvokeOnMainThread(() =>
{
EmptyViewText = "Loading data...*";
OnPropertyChanged();
});
}
This is triggered.
This is my class:
public partial class BinViewModel : ObservableObject
The binding itself works, as I do see my values. But when I change the values from code, nothing happens.
The binding is super simple:
<Label Text="{Binding EmptyViewText}" />
If I however disable the string and reenable it (re render it) it does show up with the new and correted text.
What is of issue here?
>Solution :
Your code is calling OnPropertyChanged() without an argument. Wherever that method is, it’s probably defined similar to this:
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke( this, new PropertyChangedEventArgs(propertyName));
}
The caller in this case is Entry not EmptyViewText. It’s going to fire a property changed event, but on the wrong property.
See if it makes a difference if you call it with an explicit argument:
public async Task Entry(string barcode)
{
MainThread.BeginInvokeOnMainThread(() =>
{
EmptyViewText = "Loading data...*";
OnPropertyChanged(nameof(EmptyViewText));
});
}