I'm hosting an ActiveX control in WPF form. It works well, no problem.
But I can't find the property that sets the location of the ActiveX control on the WPF form (in the code). So it's stuck at the center of the screen for now.
the host is a System.Windows.Forms.Integration.WindowsFormsHost
Layout of controls in WPF is done through layout panels like Grid, StackPanel, DockPanel, etc. They all layout the controls they contain different, so it depends on what you want. The xaml code below uses a stackpanel which layouts the controls below each other.
<StackPanel>
<WindowsFormsHost ... />
</StackPanel>
Related
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?
I'm really new to WPF and I'm trying to change the hover colour of a button in WPF. I've figured out I need to create a control template in order to efficiently do this, which I've been able to successfully do in a standard WPF application which has a App.XAML file, however the application that I'm using isn't a full WPF app, it's a winforms app that uses a ElementHost to link a WPF user control into the form. Soooooooo I was wondering how do I create a control template for WPF user control? I don't have a app.XAML which is where I put the control template the first time I did it, and if I try to slide the control template into any of the user control XAML it throws an error.
Thanks
When you're creating the template in App.xaml you're adding it as a resource by putting it inside the Application.Resources resource dictionary. You can do the exact same thing on any other element in XAML that represents a FrameworkElement (i.e. any control, layout panels, etc.). The basic setup is like this:
<UserControl ...>
<UserControl.Resources>
<ControlTemplate x:Key="MyCustomTemplate" .../>
</UserControl.Resources>
</UserControl>
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?
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.
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.