I keep getting an error when I am setting the SelectedObjects property on the PropertyGrid. My application is a mix of WPF and WinForms. The objects that I am assigning to the SelectedObjects property are WinForms objects. Here is the stack trace that I get:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Unhandled Exception on thread: System.InvalidOperationException Cross-thread operation not valid: Control 'TrendChart' accessed from a thread other than the thread it was created on.
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Design.DocumentDesigner.OnComponentChanged(Object sender, ComponentChangedEventArgs e)
at System.ComponentModel.Design.ComponentChangedEventHandler.Invoke(Object sender, ComponentChangedEventArgs e)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IComponentChangeService.OnComponentChanged(Object component, MemberDescriptor member, Object oldValue, Object newValue)
at System.ComponentModel.ReflectEventDescriptor.RemoveEventHandler(Object component, Delegate value)
at System.ComponentModel.ReflectPropertyDescriptor.RemoveValueChanged(Object component, EventHandler handler)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyDescriptorDataAccessor.#Cdb.#bn()
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyDescriptorDataAccessor.Dispose(Boolean disposing)
at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.DataAccessorBase.Finalize()
I have set the IsAsynchronous to false for the PropertyGrid:
<pg:PropertyGrid Grid.Row="1" Margin="15,40,15,0" SelectedObject="{Binding SelectedObject}" SelectedObjects ="{Binding SelectedObjects}" IsAsynchronous="False" />
Any ideas on how I can get around this?