WindowsForm Picturebox in WPF - 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.

Related

WinForms ListView TileSize when hosting in WPF

I am working on a WPF project using some WinForms user controls (to reuse code from other projects at my workplace). This works quite well by using the WindowsFormsHost control in WPF.
Recently I stumbled upon a strange case of how ListViews in Tile mode (ListView.View=Tile) are displayed when hosted in WPF. It seems like ListView.TileSize is ignored, and listview items are given a width of about 35-40 (instead of 200 which is tile size width in my test).
UserControl containing a ListView, hosted in a WPF application:
The same UserControl, running in a WinForms application:
Any thoughts for a solution to this problem?

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.

Adding Custom Windows Controls on WPF User Control

I have a WinForms User Control (a toolbar) which i would like to add on a WPF user Control, is there any way to do this?
like i want a WinForms User Control (the toolbar) along with other WPF Controls
(datagrid) on a new WPF User Control
I saw a couple of samples that show Windows Forms hosted in a WPF Control. But that is not what i want to see.
This is pretty easy to pull off. There is a handy little thing known as WindowsFormHost all you have to do is declare it in your control's XAML, and nest your forms control inside of it, like so:
<UserControl>
...
<Grid>
<WindowsFormsHost>
<forms:MyFormsToolbarControl/>
</WindowsFormHost>
</Grid>
...
WindowsFormHost lives inside of the normal WPF toolbox so it shouldn't be hard to locate. Meanwhile there is an example of how to produce the equivalent XAML in code at this location...
http://msdn.microsoft.com/en-us/library/ms751761.aspx
You can check out my answer to a similar question here:
WPF hosting a WinForm, Tab Navigation problems
This will also show you how to fix a tabbing issue with windows controls that are sitting inside wpf views.

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

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?

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