I am new to Xamarin Forms and MVMM. And i need hide and unhide the label on runtime using MVMM concept. I am create the binding property and bound into it. But It not worked.
My Xaml code is:
<Label Text="The Error" IsVisible="{Binding IsVisible}"/>
And My ViewModel Code is :
private bool isvisible;
public event PropertyChangedEventHandler OnPropertyChanged;
public void PropertyChanged([CallerMemberName] string propertyName = "")
{
this.OnPropertyChanged?.Invoke(this, new
PropertyChangedEventArgs(propertyName));
}
public bool IsVisible
{
get
{
return isvisible;
}
set
{
isvisible = value;
PropertyChanged();
}
}
Once i set isvisible property into true the label is unhided. How to achieve that?
And what wrong i done with this...
Make sure you define your viewmodel as the BindingContext of your view. The viewmodel should inherit the INotifyPropertyChanged. And then, setting the IsVisible to true or false in the viewmodel should work:
IsVisible = True; // Or False depending on your conditions