I want to change the image of a ToggleButtonTool according to it's state. I have two GiF-images for that purpose in my project. I use the following code in the event handlers:
Uri src = new Uri(@"Images/FilterOff16x16.gif", UriKind.Relative);BitmapImage img = new BitmapImage(src);ToggleButtonRowFilteringOnOff.SmallImage = img;
Unfortunately this does not work. When I look at the BitmapImage object created in the debugger I see 'img.Metadata' threw an exception of type 'System.NotSupportedException' in the Metadata property of the object.
How can I do this properly?
Markus
Hi Andrew. You are right again: The exception in the Metadata property is not the problem.
I meanwhile have it running. The problem was, that even it is a relativ Uri, the uriString parameter needs to start with a '/'. So the code needs to look like this:
Uri src = new Uri(@"/Images/FilterOff16x16.gif", UriKind.Relative);
Thanks for you help.
Yes you should be able to set the SmallImage|LargeImage properties to different ImageSource instances at runtime. With regards to the exception you listed I'm guessing that is not the specific cause of why you're not seeing the change in the image as according to the help the Metadata property of the BitmapImage class is not supported. I suspect there is an issue with the uri you are using. If you post a small sample I can take a quick look to see what may be wrong.
Hi Andrew
Thanks for your answer. You are certainly right: The problem with BitmapImage has nothing to do with the Infragistics classes.
As you don't suggest another way to do it I assume that the code I provided is in principle correct for changing the image at runtime.
It sounds like you probably have an issue with the pack notation you're using to locate the image. Taking our tools out of the equation for a second, have you tried this by just setting the Source property of an Image element? If that's not working then it has to be something with the pack notation (i.e. locating the image) or with the creation of the BitmapImage itself (in which case you may want to search the ms forums regarding the error). If it does work with an Image element then please post the sample with that working but the tool failing and we can look into why its not working in that situation.