Using WinForms Commands in WPF - kaisu1986/ATF GitHub Wiki
You can use WinForms-based command components in a WPF based application. This is made possible by the CommandServiceAdapter
component, which implements the WinForms ICommandService
so it works in a WPF environment. In other words, it adapts Sce.Atf.Wpf.Applications.ICommandService
to Sce.Atf.Applications.ICommandService
.
The CommandServiceAdapter
component exports Sce.Atf.Applications.ICommandService
. If this component is included in an application, the WinForms-based components that need ICommandService
import it from CommandServiceAdapter
, rather than the WinForms-based CommandService
component. This allows the components to function with the WPF application. The application would not include the WinForms-based CommandService
component in its MEF catalog in this case.
CommandServiceAdapter
also creates an object of the CommandClientAdapter
class, which adapts the ICommandClient
interface for WinForms-based command clients to WPF. This allows command clients implementing Sce.Atf.Applications.ICommandClient
to operate properly in WPF.
The StandardInteropParts
class includes the CommandServiceAdapter
component in a MEF TypeCatalog
:
public class StandardInteropParts
{
/// <summary>
/// Gets type catalog for all components</summary>
public static ComposablePartCatalog Catalog
{
get
{
return new TypeCatalog(
typeof(MainWindowAdapter),
typeof(CommandServiceAdapter),
typeof(ContextMenuService),
typeof(DialogService),
typeof(ControlHostServiceAdapter)
);
}
}
}
This catalog can be included in an AggregateCatalog
, as in this line from the ATF Wpf App Sample:
return new AggregateCatalog(typeCatalog, StandardInteropParts.Catalog, StandardViewModels.Catalog);
After this, the WPF application can use the WinForms-based commands component — with no additional support from the application.