WindowsFormsHost in WPF MDI on Aero main form (C#) - wpf

My crazy problem: I'm using a docking system (AvalonDock) on a WPF form with aero glass style background (what looks really nice). In one dockable MDI I need a WinForms custom control, so I just used the WindowsFormsHost that loads my control successfully. But there is one problem:
The WindowsFormsHost shows the glass background of the main form for the amount of black for all colors used in the custom control.
Changing the MDI background doesn't help because the WindowsFormsHost cuts a hole through everything in the WPF MDI.
Concluding neither trying to have white text on a black background nor the other way round makes the textbox in my custom control clearly readable.
Any suggestions?

Related

What should I implement for a small popup control in a VSTO project?

In my VSTO projects (Office 2007 / 2010) I would like to use a small popup control (think Tooltip like features; fade animation and mouse interaction).
I would prefer to use WPF. If I were to do this in WPF I would create a custom Popup Control.
In VSTO, as far as I understand it, I must use a WPF window and then have 2 options, either I put this window in a Windows Form Container or I get the Hwnd of my office app and I add this Hwnd to the Owner property of a WPF Window. Am I correct here?
Creating a whole window, animating it on and off the screen etc to look like a ToolTip seems to be overkill.
So my question is how should I do this. I would prefer WPF.
I don't know if this would work but my first thought is to build a very tiny WPF window which is transparent and start it with the Office App. I can then build a Popup Control (which is a child of this tiny window) which I show and not show at a mouse position. Pretty sure a popup can appear outside the bounds of its parent window.
Just wanted to tidy up my own question with what I did. In the VSTO addin project I added a reference to WindowsBase, PresentationFramework and presentation core.
And then I just follow any tutorial or example that adds a WPF Popup. By popup I mean a System.Windows.Controls.Primitives.Popup. For the Placement I used PlacementMode.Absolute and then used a window point to set its position.
This pretty much answers my question. Of course this popup is literally floating above your office window so you will need to make sure that you control it for example if the office window moves, is minimized and the like.

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.

WindowsForm Picturebox in WPF

I found this cool application which lets you have a webcam connection with your home network but it uses a PictureBox to show the webcam stream.
I got a PictureBox to work in WPF, but it doesn't seem to resize.
Example: http://i.stack.imgur.com/mpEsN.png
What am I doing wrong?
This is my current XAML Code:
<Grid>
<wfi:WindowsFormsHost>
<winForms:PictureBox x:Name="pictureBoxLoading">
</winForms:PictureBox>
</wfi:WindowsFormsHost>
</Grid>
I assume in your code you're not using native WPF Image control. Any native WPF control can automatically resize when included in a grid or in a Viewbox.
Because you're using Windows Forms control, you have to handle the resize yourself, because WindowsFormsHost only host Windows Forms control, NOT interacting with it as a normal WPF control.

WPF Control inside a transparent winform is not displayed

I create a simple WPF UserControl (any control will do) and insert it into a Winform (using an ElementHost).
This works fine. The WPF control is embedded in the WinForm and when the WinForm is moved around the WPF control moves with it just like a WinForm control will do.
When I change the WinForm to transparent by setting the TranparencyKey to the same value as the BackColor some problems occur:
- The WPF control is not displayed - instead a black rectangle is displayed in its place..
- If the WinForm is moved around the screen then on its original place the WPF control appears - as if it was covered by the WinForm.
Changing properties of the ElementHost (such as BackColorTransparent) did not change the behavior.
Setting both the BackColor and the TransparencyKey of the WinForm to Black got rid of the black rectangle problem but still when the WinForm was moved the WPF control was left in the original place.
Note also that these problems occurs under Windows XP SP3 (which is our target OS) but not on Windows 2003.
(We did not check on Vista and Windows 7).
Any ideas how to have a transparent Winform with a WPF control inside and still get a normal behavior?
Did you set the background property on the WPF control? By default it inherits from it's parent container and if it's not present it will do this. Try setting the background property on the UserControl to white or grey and your problem should go away.

Excel & WPF modal form

I've got this situation. (.net 3.5)
A Winform application that with OleAutomation and Office Interop create an excel, a toolbar and handlers for buttons in the toolbar.
Now we've got some functionality that shows the user modal windows (winform 2.0) with the method:
form.ShowDialog(new ExcelHwndWrapper(objExcelApplication.HWND))
And the "owner" of the modal form is set to the "excel" window.
Now I would like to create some WPF Window instead of Winforms due to layout requirements for new functionalities.
Is there any way to Show a WPF ModalDialog "over" excel Window ?
I found something for showing a WPF ModalDialog "over" a winform, but nothing over excel.
Thanks.
When using VSTO and Office 2007, I've had trouble using WPF Windows as modal dialogues. What I found that worked much better was creating a Winforms Form and putting an ElementHost control inside it, then putting my WPF content inside that.
When I used WPF Windows without the Winforms wrapper I ran into trouble with properly capturing keyboard input, among other things.
As long as you make the ElementHost stretch to fill the entire dialogue it'll look like you have a WPF Window.

Resources