cost
cost

Reputation: 4490

"Property value is not valid." Why is visual studio not letting me assign a picture to an image?

On a WPF window I have an image object. I clicked the button to assign a source, the window for it popped up, I added the image in there (clicking add). When the image loaded in, instead of showing the image, it just showed a white box. I try to assign this white box as the image source, and it just says "property value is not valid." The solution explorer clearly shows that the images are there, and I can double click and open to edit them. So why isn't VS liking how I'm trying to assign images to my wpf image object? I've added images to WPF projects several times using this method.

Upvotes: 5

Views: 22072

Answers (4)

Bizhan
Bizhan

Reputation: 17145

In case other people read this, restarting the Visual Studio might help.

Upvotes: 14

Rob Perkins
Rob Perkins

Reputation: 3130

I had a similar problem just now with VS 2012. It was traced to the fact that I'd given one of my UserControls a NameProperty of "This", in order to internally reference some dependency properties I'd defined for the controls.

Don't give your UserControls a Name="This" property in XAML. It gets confooosed.

Upvotes: 2

cost
cost

Reputation: 4490

So, it turns out the reason for this particular error was there was a space in my solution name. I guess this caused there to be a space in the path for the image, which VS just couldn't handle. Odd, but that was it.

Upvotes: 2

Bill Buhler
Bill Buhler

Reputation: 11

I just had the same issue. Because the pictures are being referenced by the project as resources they need to be compiled into the project. So in my case I added them to the solution, then built the project. At that point they were available to assign to the image control.

Upvotes: 1

Related Questions