:: Home

  login:         
  passwords:  

WPF FAQs

WPF General Questions
Concepts Element Tree
Concepts Dependency Property
Concepts Attached Property
Concepts Routed Events
Concepts Resources.
Concepts Animation
Concepts Freezable Object
Concepts Input and Commands.
Concepts Layouts
XAML Inline Styles and Templates
XAML XML Namespaces
XAML Code Behind
XAML Custom Class
XAML Type Converters
Content Model ItemControl
Content Model HeaderedItemsControl
Content Model HeaderedContentControl
Content Model Content Control
Content Model Decorator Content Model
Content Model Panel Content Model
Documents Serialization and Storage
Documents Annotations
Documents Flow Content
Documents Printing
Graphics and Multimedia Rendering Graphics
Graphics and Multimedia Animation and Timing
Graphics and Multimedia 2D Graphics
Graphics and Multimedia 3D Graphics
Graphics and Multimedia Visual Layer
Control Customization Adorners
Control Customization Stylable controls
Control Customization ControlTemplates
Data Data Binding
Data DragandDrop
Data Serialization
Globalization and Localization Attributes
Globalization and Localization Comments
Globalization and Localization Globalization Struc
Application and Deployment ClickOnce
Application and Deployment Frame
Application and Deployment Page
Application and Deployment Navigation
Application and Deployment Setup
Application and Deployment Window
Interoperability Message Loops Between
Interoperability Win32 in WPF
Interoperability WPF in Win32
Interoperability Windows Forms and WPF
Security Trusted Security
Security Partial Trust Security
Tools Microsoft Expression Blend
Tools ZAM3D
Tools XAMLPAD
Controls ToolTip
Controls TextBlock
Controls TabControl
Controls ProgressBar
Controls PrintDialog
Controls Popup
Controls TextBox
Controls Canvas
Controls ComboBox
Controls ListBox
Controls StatusBar
Controls ToolBar
Controls Context Menu
Controls Expander
Controls DocumentViewer
Controls FlowDocumentReader
Controls GroupBox
Controls GridSplitter
Controls Image
Controls Menu
Controls ScrollBar
Controls Slider
Controls RichTextBox
Controls Border
Controls Buttons

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

Winforms Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Windows Presentation Foundation Interview Questions/FAQs

Questions and answers in this FAQ have been collected from newsgroup posts, various mailing lists and the employees of Syncfusion.

47. Interoperability Win32 in WPF

    47.1 How can I use Windows Forms in a WPF application ?
    47.2 How do I host a Windows Forms control in a WPF application ?
    47.3 How can I leverage my current investment in Windows Forms applications and still tap into the cool features of WPF ?
    47.4 How can I host a Windows Forms Composite Control in Windows Presentation Foundation ?

47.1 How can I use Windows Forms in a WPF application ?

You can have a WPF application popup a Windows Form much in the same way that you can popup a WPF window from a Windows Forms application. Furthermore, you can place Windows Forms controls side-by-side with WPF controls on a WPF window or page-by-page using the WindowsFormsHost control that will ship as part of the interoperability layer.


47.2 How do I host a Windows Forms control in a WPF application ?

First make sure to add references to "System.Windows.Forms" and "System.Windows.Forms.Integration". Then you need to decide if you will use code, XAML or a combination of both to work with the Windows Forms controls. If you are strictly using code, you would write code similar to the following :

[C#]

//Instantiate the hosting control
WindowsFormsHost host = new WindowsFormsHost();
//Instantiate the Windows Forms control, in this case a button
System.Windows.Forms.Button wfButton =
new System.Windows.Forms.Button();
wfButton.Text = "Windows Forms Button";


// Add the Windows Forms button to the host control
host.Children.Add(wfButton);

// Add the host control to the WPF element that
// you want to parent the control,
// in this case it's a Grid
this.grid1.Children.Add(host);


If you are using XAML, you still need to add the references to "System.Windows.Forms" and "System.Windows.Forms.Integration", but you will also need to add mapping statements to your XAML that will allow you to refer to the objects that live in these namespaces via XAML:

[XAML]

<?Mapping XmlNamespace="wfi" ClrNamespace="System.Windows.Forms.Integration" Assembly="WindowsFormsIntegration"?>

<?Mapping XmlNamespace="wf" ClrNamespace="System.Windows.Forms" Assembly="System.Windows.Forms"?>

The "XMLNamespace" property provides a way to create a tag that you can use as a namespace prefix in the XAML to refer to the controls within the "System.Windows.Forms" and "System.Windows.Forms.Integration" namespaces. To enable this, you must also create "xmlns" properties in the XAML that maps back to these prefixes as given below :

[XAML]

<Window x:Class="AvalonApplication17.Window1"

xmlns="http://schemas.microsoft.com/winfx/avalon/2005"

xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

xmlns:wfi="wfi"

xmlns:wf="wf" Title="AvalonApplication17"

Loaded="WindowLoaded"

> 

Then you can use XAML to instantiate the WindowsFormsHost control and its subsequent child controls:

<Grid x:Name="grid1">

<wfi:WindowsFormsHost>

<wf:Button Text="Windows Forms Button"/>

</wfi:WindowsFormsHost>

</Grid>


47.3 How can I leverage my current investment in Windows Forms applications and still tap into the cool features of WPF ?

You can choose to keep your Windows Forms application primarily intact and migrate portions of your application to WPF where it makes sense. You can do this by identifying those areas of your application that are a good fit for WPF features and convert only those areas to WPF. For example, you may want to convert only a few of your forms to WPF and keep the rest of the application based on Windows Forms. Using this method, you could simply popup instances of WPF pages or windows from your Windows Forms application. Additionally, you may want to actually swap-out Windows Forms controls for WPF controls on a form resulting in a hybrid form when the controls co-exist in peaceful harmony.


47.4 How can I host a Windows Forms Composite Control in Windows Presentation Foundation ?

It can be done with the following code :

[XAML]

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

x:Class="WpfHost.Page1"

xmlns:mcl="clr-namespace:MyControls;assembly=MyControls"

Loaded="Init">

...

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

x:Class="Page1"

xmlns:mcl="clr-namespace:MyControls;assembly=MyControls"

Loaded="Init">

...

<WindowsFormsHost Name="wfh"

DockPanel.Dock="Top"

Height="300">

<mcl:MyControl1 Name="mc"/>

</WindowsFormsHost>

...

<WindowsFormsHost Name="wfh"

DockPanel.Dock="Top"

Height="300">

<mcl:MyControl1 Name="mc"/>

</WindowsFormsHost>

bottom user control
::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd