Tag Archives: Control

Hosting WinForms Control in WPF

In the following sample we’ll see how to host a WinForms PropertyGrid control in WPF window.

Also, If you need a property-grid that can’t change (read-only), here are the basics of how to do it.

REMARK: It’s not fully done yet (you can still right-click a value and select ‘cut’ or ‘delete’ which alter it), if you have any idea how to prevent this menu, please, let us all know by posting a reply.

 

Hosting the WinForm PropertyGrid in WPF

The XAML

IMPORTANT Notes

Add reference to:

  • System.Windows.Forms
  • WindowsFormsIntegration
Note Note
WindowsFormsIntegration.dll is installed with the Windows Presentation Foundation (WPF) assemblies. The default location for the assembly is %programfiles%Reference AssembliesMicrosoftFrameworkv3.0WindowsFormsIntegration.dll.
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:swf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Loaded="Window_Loaded"
        Title="Hosting a Windows Forms Property Grid in WPF" Height="350" Width="525">

  <Grid>
    <WindowsFormsHost>
      <swf:PropertyGrid x:Name="propertyGrid" />
    </WindowsFormsHost>
  </Grid>
</Window>

The code

using System.Windows;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            propertyGrid.SelectedObject = this;
        }
    }
}

 

The Result

The resulting WPF window with the PropertyGrid

 

 

Read Also

Readonly-propertygrid-in-wpf

Layout Considerations for the WindowsFormsHost Element

 

Resources

http://msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.aspx

http://blog.typps.com/2011/04/getting-most-out-of-winforms.html

A Developer’s Introduction to Windows Workflow Foundation (WF4) in .NET 4

A very good tutorial/article about WF4 (not so many out there these days).

 

A Developer’s Introduction to Windows Workflow Foundation (WF) in .NET 4.

 

TOC

Overview

 

What’s New in WF4

Designers

Data Flow

Flowchart

Programming Model

Windows Communication Foundation (WCF) Integration

 

Getting Started with Workflow

Workflow Structure

Workflow Templates and the Workflow Designer

Data flow in workflows

Variables – storing data

Arguments – passing data

Expressions – acting on data

Building your first workflow

Tour of the workflow activity palette

Activity Primitives and Collection Activities

Control flow activities

Migration

Flowchart

Messaging Activities

Transactions and Error Handling

Creating and executing workflows

Options for designing workflows

Options for executing workflows

Workflow Extensions

Persistence

Tracking

Creating custom activities

Activity class hierarchy

Composing activities using Activity designer

Writing custom Activity classes

Additional activity concepts

Activity designers

Rehosting the workflow designer

Workflow Services

Conclusion

About the Author

Additional Resources