I have a XAML view bound to a ViewModel
When the view loads it sets the binding context to be an object (type GAME_TBL)
When the ViewModel loads, I await a message arriving with a unique ID
I then use this to calll an API and return a game object which I cast to replace the one that is bound
However, even tho debug shows me this is all working, and the PropertyChanged fires, the UI never updates
From the View:
<ContentPage.BindingContext>
<viewmodels:VotingViewModel/>
</ContentPage.BindingContext>
.....
<Label Text="{Binding currentGame.GAME_NAME}" />
In the VotingViewModel:
public class VotingViewModel : BaseViewModel
{
GAME_TBL gameSelected;
public GAME_TBL currentGame
{
get {
return _currentGame;
}
set
{
_currentGame = value;
OnPropertyChanged(nameof(_currentGame));
}
}
public VotingViewModel()
{
MessagingCenter.Subscribe<Views.GamesView, string>(this, "Selected Game", (sender, arg) =>
{
gameID = Convert.ToInt32(arg);
currentGame = loadGameInfo(); // this interacts with an API to set object specifics
});
}
}
In the BaseViewModel
protected virtual void OnPropertyChanged(
string propertyName = null)
{
System.Diagnostics.Debug.WriteLine("Debug: Name of property: " + propertyName);
PropertyChanged?.Invoke(this,
new PropertyChangedEventArgs(propertyName));
}
nameof(_currentGame)
is the internal backing field, NOT the public property you are binding to - Jason