Reputation: 53
I want to swap images on the button dynamically using mvvm light. When the page first loads,it should display the images as per the database values i.e. checked or unchecked. I have 2 columns for the images like ImageChecked and ImageUnchecked. By clicking on the button i.e checked or unchecked it should change accordingly.If it checked then unchecked n vice versa based on the database values.Images will load on button as Content.
Kindly Help?
Thanks
Upvotes: 1
Views: 406
Reputation: 12954
Are you trying to implement the functionality of checkbox using a button?
If so, you can take a look at the ToggleButton which has the IsChecked and Content properties so that you can change your content using a trigger based on the IsChecked property.
Else if you have the IsChecked property ready from the ViewModel then you can change the image of the button using the Image property using a DataTrigger.
Update
The hierarchy goes like this: ToggleButton->Image->BitmapImage. Set the urisource of the BitmapImage and set it as a source for an Image which in turn is set as a content of the ToggleButton. Do this in xaml. Check this link for creating an Image.
Now set the DataTrigger of the ToggleButton for IsChecked value True
and change the BitmapImage's UriSource with the assistance of TargetName
property.
Upvotes: 0