C#C
C#3y ago
Neeblue

❔ Problem Binding to Image Size

I am making an app that displays a series of books. An image and title of the book is to be displayed in a listBox of the main window. So far this works well. I decided to add a slider to allow the user to choose a size for the image of the book. I bind the width and height of the image to the ViewModel and make a switch statement for the various locations of the slider to determine the size of the image.

When I start the app I run into two problems:
  1. The image of each book takes up the entire width of the window OR
  2. I get a System.InvalidOperationException: 'Invalid size returned for Measure.'
I believe the problem is connected to the "OnSliderChanged" method of my ViewModel. Initially, the slider is set to 0 (but my slider is between 1 and 5) and so it was throwing an exception. I end the method early if it is set to 0 and the exception thrown above is shown.
1.jpg
2.jpg
Was this page helpful?