none
Can u get the ToolboxItem object from a ToolboxItemWrapper?

    Question

  • We're loading a ToolboxControl object for our rehosted designer by adding ToolboxItemWrapper objects.  I'm wondering if it's possible to somehow retrieve the wrapped ToolboxItem itself from the wrapper object?  I tried casting, that doesn't work ... and there doesn't seem to be any property getter.

    Wednesday, October 13, 2010 9:00 PM

Answers

  • if you don't want to use reflection, maybe you can consider

    ToolboxItem item = new ToolboxItem(itemWrapper.Type)

    and you may also bind other properties from itemwrapper to the toolboxitem.

     

    • Marked as answer by Kofoed Tuesday, October 19, 2010 8:47 PM
    Thursday, October 14, 2010 5:52 AM

All replies

  • what do you mean retrieving the wrapped toolboxitem from the wrapper object?

    can you give me more details at which stage you want to retrieve the toolboxitem?

    or can you send me your casting code to sophy_yuye@hotmail.com so I can investigate for you?

     

    Thursday, October 14, 2010 3:27 AM
  • The ToolboxItemWrapper.ToolboxItem property is an internal property, so you can't direct access it. Here is a sample code if you do want to use this internal property:

       //e.g Assume we have already have a ToolboxItemWrapper
       ToolboxItemWrapper itemWrapper = new System.Activities.Presentation.Toolbox.ToolboxItemWrapper(typeof(Assign));
       
       ToolboxControl toolbox = new ToolboxControl();
       ToolboxCategory category = new ToolboxCategory();   
       category.Add(itemWrapper);
       toolbox.Categories.Add(category);
       
       //Use reflection to get the ToolboxItem instance from ToolboxItemWrapper
       PropertyInfo toolboxItemPropertyInfo = itemWrapper.GetType().GetProperty("ToolboxItem", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
       ToolboxItem item = toolboxItemPropertyInfo.GetValue(itemWrapper, null) as ToolboxItem;
    

    Note: The toolboxItemWrapper.ToolboxItem property will not get calculated until you add this itemWrapper to a ToolboxControl. Before you add it, it's null.

    Use internal property maybe not a good practice, please let Ye and me know why do you want ToolboxItem object.

     


    This posting is provided "AS IS" and confers no rights or warranties.
    Thursday, October 14, 2010 5:29 AM
    Moderator
  • if you don't want to use reflection, maybe you can consider

    ToolboxItem item = new ToolboxItem(itemWrapper.Type)

    and you may also bind other properties from itemwrapper to the toolboxitem.

     

    • Marked as answer by Kofoed Tuesday, October 19, 2010 8:47 PM
    Thursday, October 14, 2010 5:52 AM