0

I'm trying to port a Windows Forms application to WPF (VS 2010 / .NET 4), and trying to follow the MVVM methodology. Unfortunately, most of the "buttons" in the legacy UI were done w/ images (PictureBoxes) to more closely match the actual hardware that we're simulating. As a result, I'm trying to figure out the best approach to modeling buttons as clickable images so that they can issue an ICommand? A couple of sub-requirements I have are:

  1. The image needs to change when pressed (i.e. show the button down)

  2. In some cases the value tied to the button needs to keep changing as long as the button is down. So I need to know not only when the button is pressed, but also when it is released.

I've seen some posts saying to use a button or hyperlink w/ an image and change the styling in order to get the command. If this is the best way, how can I incorporate the sub-requirements?

Any advice on best practices here would be appreciated.

user7134019
  • 207
  • 1
  • 3
  • 13
  • So a) This is a really broad question. b) I'd suggest not using raster images for that sort of thing. They look shotty betweeen different screen resolutions etc and quite often you don't even need them to make great looking stuff in vector form. For example (these were done in Silverlight years ago so you'll have to permit the plugin but making them in WPF wouldn't be too tough and is very similar) you can do some neat stuff [without needing any images at all](http://professionalsweb.com/ToggleButtons-CW/ButtonsSite/). – Chris W. Feb 20 '17 at 17:18
  • Nothing really to do with MVVM. WPF controls are pretty easy to customize via their template. The linked duplicate shows how to customize the template. You can use triggers to change the image source like http://stackoverflow.com/questions/1786477/change-image-using-trigger-wpf-mvvm or use the visual state manager to switch image sources in the template http://miteshsureja.blogspot.com/2011/05/visual-state-manager-new-feature-in.html And if none of these suit you, you can always create a pseudo-button from a UserControl. –  Feb 20 '17 at 18:42

0 Answers0