Hi,
I'm trying to show hide a contentview / text based on if the current state is Loading Data, Data Load Success, Data Load Fail. I've tried this but it doesn't seem to work.
The View doesn't update the IsVisible status when i change the selected enum option.
There's a few other values that i would want to set based on the state (e.g. error messages, other views visible / not visible) so thought this might be a better option that setting isVisible for each item in the try / catch block - but it doesn't seem to update the view currently
View:
<myView x:Name="overlay" IsVisible="{Binding IsVisibleOverlay}"> </myView>
ViewModel:
public enum ViewModelState
{
BeforeDataLoad,
LoadingData,
DataLoadSuccess,
DataLoadFailAndRetry
}
private ViewModelState vmState;
public ViewModelState VMState
{
get => vmState;
set
{
this.vmState = value;
OnPropertyChanged(nameof(vmState));
OnPropertyChanged(nameof(IsVisibleOverlay));
}
}
public async void LoadData()
{
Api api = new Api();
try
{
vmState = ViewModelState.LoadingData
api.GetData
vmState.DataLoadSuccess
}
catch
{
vmState = ViewModelState.DataLoadFailAndRetry;
}
}
public bool IsVisibleOverlay
{
get
{
switch(vmState)
{
case ViewModelState.LoadingData:
return true;
case ViewModelState.DataLoadSuccess:
return false;
default:
return false;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}