tags:

views:

34

answers:

1

Hi,

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

A: 

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.

Veer
@Veer. Yes ur correct. Want to implement the checkbox functionality using a button. Will try n let u know.Thanks
Tarun
@Veer. Yes we can make use of the Ischecked property here what we are using in case of checkbox. How to use the Data Trigger ere.Kindly Suggest?Thanks
Tarun
@Tarun: Did you check the MSDN link provided for DataTrigger?
Veer
@Veer. Yes I have checked. but not able to get how to bind the images from database. Kindly Suggest?
Tarun
@Tarun: 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 http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.aspx
Veer