NoOne
NoOne

Reputation: 4091

WPF - How to put a XAML Icon inside an ImageSource?

I am using Xceed's MessageBox and, as you may know, in order to customize its display image you have to use its ImageSource property which is of type ImageSource.

Now, I have some cool icons in XAML (taken from here, here and some that I've made by myself). So I want to use them in an ImageSource in order to have them on the MessageBox.

I have searched the web, but the closest I came was with the DrawingImage class:

http://msdn.microsoft.com/en-us/library/system.windows.media.drawingimage%28v=vs.110%29.aspx

But this uses geometries, not normal XAML elements (like Canvas, Path, Rectangle, etc) that my icons use.

I have found a similar question here, but it doesn't seem to help much.

So, is there a way to put my icons (as they currently are) inside an ImageSource?

And if not, is there a way to convert my icons into geometries (using simple C# code or tools like Blend)?

Upvotes: 4

Views: 838

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292345

I don't think it's possible to do it in pure XAML (unless you want to manually convert your XAML image to a DrawingImage). However, you could render the image to a bitmap using the RenderTargetBitmap class, then use that bitmap as the image source.

Upvotes: 2

Related Questions