Passing a WPF object from an AddIn to the Host

Latest post 10-01-2008 2:24 PM by Gary. 3 replies.
  • 09-26-2008 3:22 PM

    Passing a WPF object from an AddIn to the Host

    Hi,

    I am tring to return a WPF element (User Control) instance which has been created by an Add-In back to the Host so that it can add it as a child element of its parent window. 

    http://blogs.msdn.com/clraddins/archive/2007/08/06/appdomain-isolated-wpf-add-ins-jesse-kaplan.aspx

    I understand that INativeHandleContract needs to get passed across.

    How do you do this using VSTA?

    Filed under:
  • 09-27-2008 8:27 AM In reply to

    • Gary
    • Top 10 Contributor
    • Joined on 07-13-2006
    • Posts 305

    Re: Passing a WPF object from an AddIn to the Host

    Will have to look into this further.  In the meantime take a look at my WPF Addin - here

  • 09-29-2008 9:16 AM In reply to

    Re: Passing a WPF object from an AddIn to the Host

    Thanks for the responce.

    I did look at the sample,

    What does the XML look like for the code below?

    How did the INativeHandleContract get there?

    Thanks,

     

    John McCauley

     

    proxy.cs

     

     

     

     

     

    public virtual void AddMainWindowButtonContract(global::System.AddIn.Contract.INativeHandleContract

    uiElementNativeHandleContract)

    {

     

     

    this

    .RemoteObject.AddMainWindowButtonContract(uiElementNativeHandleContract);

    }

     

     

    public virtual void AddMainWindowButton(global::System.Windows.FrameworkElement

    frameworkElement)

    {

     

     

    this

    .RemoteObject.AddMainWindowButtonContract(inhc);

    Filed under:
  • 10-01-2008 2:24 PM In reply to

    • Gary
    • Top 10 Contributor
    • Joined on 07-13-2006
    • Posts 305

    Re: Passing a WPF object from an AddIn to the Host

    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. 

Page 1 of 1 (4 items) | RSS
Copyright Summit Software Company, 2008. All rights reserved.