I have 2 images visibility using MVVM in Xamarin forms. 1 image represents nothing selected and the other should turn first image off and turn on second image when a selection is made on the form.
XAML:
<Image x:Name="greenCheckImage" BackgroundColor="#F5E9E9" Source="GreenCheckmark.gif" Grid.Row="4" Grid.Column="2" HeightRequest="50" WidthRequest="50" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" IsVisible="{Binding GreenCheck}"></Image>
<Image x:Name="grayCheckImage" BackgroundColor="#F5E9E9" Source="GrayCheckmark.gif" Grid.Row="4" Grid.Column="2" HeightRequest="50" WidthRequest="50" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand" IsVisible="{Binding GrayCheck}"></Image>
Model:
public bool GrayCheck { get; set; }
public bool GreenCheck { get; set; }
View Model:
private bool grayCheck;
public bool GrayCheck
{
get
{
return grayCheck;
}
set
{
if (grayCheck != value)
{
grayCheck = value;
OnPropertyChanged();
}
}
}
private bool greenCheck;
public bool GreenCheck
{
get
{
return greenCheck;
}
set
{
if (greenCheck!= value)
{
greenCheck= value;
OnPropertyChanged();
}
}
}
Here is my implementation of INotifyPropertyChanged which should be handling the page update right?
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string name = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
Everything is getting set properly when page loads and clicking on the a selection is also firing correctly and the true/false on IsVisible is also being set properly; however the unslected image still remains on the graycheck rather than what should be being displayed is the greencheck and the graycheck should not be visible anymore.
What am I missing here? TIA! Rick...
GreyCheck = falsewhenever you setGreenCheck = true- JasonVisualStateManagerorTapGestureRecognizer? - Wendy Zang - MSFT