Panel does not resize controls while creating control image - wpf

I need to create an image of a custom WPF control and save it to file. I do it by this way (http://denisvuyka.wordpress.com/2007/12/03/wpf-diagramming-saving-you-canvas-to-image-xps-document-or-raw-xaml/).
The control contains several panels (ie. StackPanel). When this control is rendered on the form it looks perfectly. But when I render it in memory and save to file all controls in panels are not aligned. They take area that they need only and they doesn't stretch.
When I used WPF 3.5 it worked. This issue appeared after I updated my project to WPF 4.0.
Could anybody explain me what changes in WPF 4.0 cause this behaviour and how I can resolve it?

Related

WPF WindowsFormsHost creates fuzzy text

I am hosting a winforms DataGridView inside a WindowsFormsHost on a WPF Window. Functionality is fine, but the text in the grid cells looks a little more fuzzy. Normally WinForms text has very little antialiasing.
How can I get the DataGridView text to look as it normally would on a Windows Form, or at least be sharper? I have tried playing with the TextOptions.TextFormattingModeand SnapsToDevicePixelssettings of the WindowsFormsHost, but don't see any difference.
As an example of what I mean here are two screenshots:
Datagridview inside a WPF WindowsFormsHost:
DataGridView in Windows Forms:
The appearance of hosted WinForms/Win32 content should not be affected by WPF. There is an "airspace" limitation that dictates that a single window pixel can only be owned by a single graphics API, and it can only be drawn by that API. Hence, WinForms content is drawn by WinForms/GDI+, even when hosted by WPF. This explains why hosted content will be drawn on top of any WPF content in the same window, even if the WPF content is positioned in front of it.
Changing WPF rendering properties like TextFormattingMode cannot affect the appearance of interop content. You should be looking at the layout/rendering properties of the hosted WinForms content.
Update
Presumably the fuzzy effect is do to WPF defaulting to grayscale AA for the DataGridView. In the Paint and/or CellPainting events of the DataGridView, setting the graphics text hint to cleartype:
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
eliminated most of the fuzziness.

Image Control disapear after it's dragged in Design

I'm a WPF newbie and, unlike WinForms, I have a hard time to setup things in the design window.
My first obstacle is the Image control. After I drag it in the Design window it disappears and there's no way for me to edit its properties (like with the button control for example). The only way to make changes is via the XAML code which isn't very visual and intuitive.
Is there a way to keep editing the Image control in design mode? (example, move it around, select it to view its property panel, etc.)
All you should need to do is give the image control a fixed height and width and it should stay in the designer.
The best thing about the XAML is which separated from code for better re usability like asp.net. It's best you to learn different layouts such as grid, wrappanel, stackpanel etc. Then, you will feel the power of xaml. Else, you can choose the XAML building tools.
Link to refer

Is there a way to make a winforms usercontrol in a WindowsFormsHost larger?

I have a few usercontrols from an old Windows CE project that I'd like to have in a WPF window, so I've copied the code/design over to the WPF project and dropped the usercontrol into a WindowFormsHost object. It appears to work fine, but the control looks rather small and I'd like to make it bigger. I tried a viewbox but this doesn't actually make it larger (which I kind of expected since it's based around the vector based WPF system). Does anyone know if any way to make a Winforms usercontrol larger in this setting?
Unless the Winforms control(s) use docking or anchoring so they resize with the container there is no easy way to do this.
Perhaps you could change the code of the Winforms controls so they do dock and/or anchor. But even when you do this, fonts will not size along.

Dynamically adding ElementHost'd WPF UserControl to WinForms results in Black

I have a WPF user control inside an ElementHost that is inside a WinForms control to wrap it. I'm dynamically adding it to a tab control tab.
But when I do this, my WPF control is black.
How do I fix that?
There are many alternative solutions on the web to this one. However, what fixed it for us was to avoid "Fill" docking the element host within it's parent control. If you are using docking, then give it a try!
Unfortunately this can be one of those evil problems solved by experimentation and it'll turn out to be a one line fix!
It was my own mistake. I forgot to add the WinForms tab control panel (a 3rd party one) to the right class.

VB6 ActiveX Control Inside WPF With Scrollbars

I have some legacy VB6, which I am hosting inside an ActiveX control, which is in my WPF application.
Despite putting the control inside of a DockPanel, which is inside a ScrollViewer, the VB6 displays outside the bounds of both, sitting on top of the rest of the application.
Does anyone know how I can keep the VB6 inside of the ScrollViewer without it spilling out onto the rest of the application?
ScrollViewer - expands to fill an area
Has a child element...
DockPanel - fixed to the height and width of the VB6 form
Has a child element...
VB6
Any help or guidance will be greatly appreciated.
I don't think you can do this, the ActiveX control is just going to sit on top of any XAML you wrap it in. As a workaround you could try creating a control in WinForms that contains your ActiveX control and handles the scrolling, then embed that in the WPF app. It's a bit hacky, and might be a pain if you need to resize, but it SHOULD work :-)

Resources