# ObjectBrowser to WpfTreeView conversion.

**URL:** <https://tech-community.robotics.abb.com/t/objectbrowser-to-wpftreeview-conversion/9352>\
**Category:** Developer Tools\
**Created:** [March 1, 2020, 9:02pm UTC](https://tech-community.robotics.abb.com/t/objectbrowser-to-wpftreeview-conversion/9352 "2020-03-01T21:02:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [March 1, 2020, 9:02pm UTC](https://tech-community.robotics.abb.com/t/objectbrowser-to-wpftreeview-conversion/9352/1 "2020-03-01T21:02:04Z")

</div>

Hello,  
I want to make an addin which makes a new ProjectBrowser with filter ability.  
Here the Code:  
//Get ObjectBrowser Window  
Window objectBrowserWin = UIEnvironment.Windows[“ObjectBrowser”];  
//Get Control normally as ABBInternal.ProjectBrowser.LayoutBrowser;  
var layoutBrowser = objectBrowserWin.Control;  
if ( !(layoutBrowser is null) && layoutBrowser.IsHandleCreated)  
{  
// Get first Control (Second is tool buttons)  
System.Windows.Forms.Integration.ElementHost elementHost = (System.Windows.Forms.Integration.ElementHost)layoutBrowser.Controls[0];  
WpfTreeView wpfTreeView = (WpfTreeView)elementHost.Child;  
// Get TreeModel normally as ABBInternal.ProjectBrowser.LayoutTreeModel  
TreeModel treeModel = wpfTreeView.TreeModel;  
if (!(treeModel is null))  
{  
//Create new window  
ToolWindow toolWindow = new ToolWindow(“FilteredObjectBrowserWindow”)  
{  
Caption = “Filtered ObjectBrowser.”  
};  
UIEnvironment.Windows.AddDocked(toolWindow, System.Windows.Forms.DockStyle.Top, UIEnvironment.Windows[“ObjectBrowser”] as ToolWindow);

WpfTreeView filterTreeView = new WpfTreeView();  
// Create a copy treeModel  
WpfTreeModel wpfTreeModel = new WpfTreeModel();  
filterTreeView.TreeModel = wpfTreeModel;  
wpfTreeModel.ExpandRootNodes = treeModel.ExpandRootNodes;  
wpfTreeModel.ExpandedNodes.AddRange(treeModel.ExpandedNodes);

// Create the ElementHost control for hosting the  
// WPF UserControl.  
System.Windows.Forms.Integration.ElementHost host = new System.Windows.Forms.Integration.ElementHost  
{  
Dock = System.Windows.Forms.DockStyle.Fill,

// Assign the WPF UserControl to the ElementHost control’s  
// Child property.  
Child = filterTreeView  
};

// Add the ElementHost control to the form’s  
// collection of child controls.  
toolWindow.Control.Controls.Add(host);  
}  
}

But this crash RS directly when I put mouse hover a node with that error:  
System.InvalidCastException  
HResult=0x80004002  
Message=Unable to cast object of type ‘ABB.Robotics.RobotStudio.Stations.Station’ to type ‘ABB.Robotics.RobotStudio.UI.WpfTreeNode’.  
Source=ABB.Robotics.RobotStudio.UI  
StackTrace:  
at ABB.Robotics.RobotStudio.UI.WpfTreeModel.GetNodeToolTip(Object obj)  
at ABB.Robotics.RobotStudio.UI.WpfTreeView.Grid\_ToolTipOpening(Object sender, ToolTipEventArgs e)  
at System.Windows.Controls.ToolTipEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)  
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)  
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)  
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)  
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)  
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)  
at System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent(Boolean fromKeyboard)  
at System.Windows.Controls.PopupControlService.\<\>c\_\_DisplayClass8\_0.b\_\_0(Object s, EventArgs e)  
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)  
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)  
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)  
at System.Windows.Threading.DispatcherOperation.InvokeImpl()  
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)  
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)  
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)  
at System.Windows.Threading.DispatcherOperation.Invoke()  
at System.Windows.Threading.Dispatcher.ProcessQueue()  
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)  
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)  
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)  
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)  
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)  
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)  
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)  
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)  
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)  
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)  
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)  
at System.Windows.Forms.Application.Run(Form mainForm)  
at ABBInternal.StudioAppFramework.StudioAppFrameworkHost.Run()  
at RobotStudio.Program.Main(String args)

How can I make what I want?

---

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [March 25, 2020, 3:58pm UTC](https://tech-community.robotics.abb.com/t/objectbrowser-to-wpftreeview-conversion/9352/2 "2020-03-25T15:58:06Z")

</div>

Up…

---

<div class="post-metadata">

**Author:** ![Maxim](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/maxim/32/4429_2.png) [@Maxim](https://tech-community.robotics.abb.com/u/Maxim)\
**Post date:** [April 15, 2020, 7:34am UTC](https://tech-community.robotics.abb.com/t/objectbrowser-to-wpftreeview-conversion/9352/3 "2020-04-15T07:34:18Z")

</div>

I’ll try to remember to look into this issue when I get access to RS source code. I would need to run your addin against the source code to look for hick ups.
