Using a XAML vector image as a window icon - wpf

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

Related

Is it possible for directx12 to render to only a portion of a window?

I'm trying to host a dx12 viewport in WPF, but it seems I can only render to the full window.
I've tried to set D3D12VIEWPORT.Width to half of the window's width, and i got this
And I've tried to set the width of the ScissorRect to half of the window, then I got this.
Is there a way to draw to only part of the window and left the rest part of window for UI?
I think I found a solution.
Just in case anyone runs into the same problem when trying to make WPF and dx work together:
1.Add a WindowsFormsControlLibrary project to the solution.
2.Handles the message in a winform usercontrol by overriding WndProc.
3.Embed the winform usercontrol into WPF main window.
4.Render into the embedded winform usercontrol.

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

Images without borders in PropertyGrid control

Using windows forms PropertyGrid control I can add images into select for any property using some UI type converters, etc. This control adds black border for each picture in the list. Does anybody know how to remove it?
See the samples of desired and existing picture here
and
Use the following line of code in your custom UITypeEditor class before drawing the image:
e.Graphics.ExcludeClip(e.Bounds);

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.

Resources