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

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)?

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.

Related

Displaying dynamic text with hyperlinks in Silverlight

I have an application that should work a bit like a message board: text gets parsed, hyperlinks are made "live" and displayed. Only it's in Silverlight. Because of that, I can't use TextBlock like they do here WPF - Making hyperlinks clickable, somehow it's different in Silverlight and it's not possible to do a Hyperlink with a Run inside it.
I've tried the RichTextBlock, as it says here Wrapping Text and Hyperlinks in Silverlight, but couldn't for the life of me figure out how to create the paragraphs and hyperlinks from code, since I need to populate it dynamically.
Then I thought I'd settle for a less elegant solution involving TextBlocks and HyperlinkButtons in a WrapPanel. I added a namespace reference, like it says here WrapPanel in Silverlight 4 toolkit, but when I reference it in XAML, there's no WrapPanel in it, only DataField, DataForm and VisualStateManager.
This Text areas and hyperlinks? doesn't work either, the Silverlight RichTextBox is different and LinkLabel is missing.
Maybe there's another solution that I don't know? I'm keeping an open mind. Any help appreciated.

control with image, title and hyperlinks like in VS

I am completely new to wpf and the question is this.
Is there available xaml for the control like on attached image?
As you can see, when we click on a control the image on the left becomes larger and all the text slides to the left. Or how could I create similar control?
The easiest way to accomplish that is a Storyboard.
Open Expression-Blend, build a Control. Hide all Elements you dont see first so its small. Create a new Storyboard, make a Keyframe and change the Properties of the elements you then want to change, create a new Keyframe.
Its like an Animation now. You can now start the Storyboard any time, on any event to expand your control.
If you dont know how to use Expression Blend and the Storyboard, there are some fine Tutorials and Videos.
Good luck!

Drawing Control Visual Elements onto a Rectangle

I've got a custom composite WPF control (AvalonEdit) in my application that I'd like to animate whenever its Text property is changed. What I intend to do is:
Create a copy of the control's visual representation before the text is changed and paint it over a rectangle.
Fade out the above rectangle, update the text property and fade in the control using the DoubleAnimation and Storyboard classes.
I've got #2 figured out but haven't got a clue about how I'd achieve #1. Any help would be appreciated.
For (1) there are a couple of approaches that spring to mind:
VisualBrush - A visual brush is a brush which is defined by a complex UI element. In other words, you can create a visual tree of elements and use this to create your brush. See the tutorial here. I think in your case you would have to define your UI twice, i.e. have an instance of your AvalonEdit control as the 'visual' for you VisualBrush, so perhaps not ideal
WriteableBitmap - A writeable bitmap allows you to copy part of your UI into a bitmap where you can manipulate he pixel data. Whilst you do not need pixel-level manipulation it is still a convenient mechanism for cloning your UI. See this tutorial I wrote here.

Using image or xaml for buttons

I was wondering the need for custom xaml code for buttons.
Using images like in html should be faster.
Yours thoughts please.
The whole point of WPF is that it is independent of pixel resolution or DPI. If you use raster images for the buttons it is no longer DPI independent and can look bad on some resolutions. If, instead, you use WPF objects and geometries, those will look almost exactly the same on any DPI.
What happens when you want to change something small to do with the button? Using custom XAML allows me to apply the same template to all my buttons, and change them all by just changing that template. It also means that I can tweak small things without the need to constantly regenerate those images.
As for speed, you're best off not pre-empting the framework's optimisations until you actually encounter a performance issue.
EDIT: I should also note that the Image class doesn't inherit from Button, and as such you can't do the direct binding to an ICommand property in the ViewModel.

Using a XAML vector image as a window icon

LearnWPF.com posted this article about converting bitmap images to XAML and using them in your applications.
The outer element of the XAML image is a Canvas. However, the Window.Icon property only accepts an ImageSource object. Does anyone know how I can 'wrap' the Canvas in an ImageSource so I can use it as a window icon?
Alternatively, is there a better way to use a XAML image as a window icon?
The WPF window Chrome(header bar, Icon etc) are part of the typical Win32 Window system. So it was not built to use with Vector Icon, you need to specify an .Ico, .png or some other supported image file to the Window.Icon property.
But if you really want to make a Vector(XAML) animating Icon, you need to think about the concept of Chrome less window. That means gets rid of the old style window chrome(WIndowStyle="None") and build our own chrome entirely with WPF, then you can place your Vector directly over the left top corner and it will just work as you do with any other XAML Visuals in the application.
Read more about how to create Chromeless window on bellow links
How do I implement a chromeless window with WPF?
Creating a Custom Window in WPF

Resources