By JohnHMcCauley in VSTA Tech Discussions
The solution I came up with, has its drawbacks.
Add-In side
IRegion mainRegion = this.RegionManager.GetRegion("MainRegion"
);
FrameworkElement element = new HelloWorldView
();
INativeHandleContract handle = FrameworkElementAdapters
.ViewToContractAdapter(element);
this.LoggerFacade.Log("mainRegion.Add(element, HelloWorld)", Microsoft.Practices.Composite.Logging.Category.Debug, Microsoft.Practices.Composite.Logging.Priority
.None);
mainRegion.Add(handle.GetHandle(),
"HelloWorld"
);
Host Side
private void InnerAdd(object view, string name, IRegionManager regionManager)
{
if (ItemMetadataCollection.FirstOrDefault(x => x.Item == view) != null)
throw new InvalidOperationException(Resources.RegionViewExistsException);
if (view.GetType().IsValueType)
{
IntPtr hWnd = (IntPtr)view;
if (hWnd != null)
{
INativeHandleContract nativeHandle = new NativeHandle(hWnd);
view =
FrameworkElementAdapters.ContractToViewAdapter(nativeHandle);
}
}
--------------------------------------------------------------------------------------------------------------------------
By Gary
Unfortunately, those methods in the proxy should have been removed. They were an unsuccessful, simplistic attempt to support passing the WPF object from Addin to Host. The sample uses the WPFAddInHostView-related contract/pipeline elements from the MSDN sample instead of VSTA's elements, although they are pysically contained in the VSTA pipeline.
I think that the way forward is to create a new contract and pipeline elements that combine VSTA's IEntryPoint-related contract/pipeline elements with the WPFAddInHostView-related contract/pipeline elements from the MSDN sample (maybe something like "IWPFViewEntryPoint"). The result being a custom pipeline with proxy that implements both of these and can pass through a INativeHandleContract. This is on my todo list, and I’d be interested in your findings, if any. Not sure how helpful the Pipeline Builder would be in this effort.