Hi,
I recently discovered a bug in version 2.4.0.0 (I guess newer versions are affected as well):
If you start two property grid instances in two windows with different UI Threads, you will get an InvalidOperationException like the following:
```
System.Windows.Markup.XamlParseException occurred
_HResult=-2146233087
_message=Initialization of 'Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid' threw an exception.
HResult=-2146233087
IsTransient=false
Message=Initialization of 'Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid' threw an exception.
Source=PresentationFramework
LineNumber=0
LinePosition=0
StackTrace: at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
InnerException: System.InvalidOperationException
_HResult=-2146233079
_message=The calling thread cannot access this object because a different thread owns it.
HResult=-2146233079
IsTransient=false
Message=The calling thread cannot access this object because a different thread owns it.
Source=WindowsBase
StackTrace:
at System.Windows.Threading.DispatcherObject.VerifyAccess()
at System.Windows.SystemResources.FindCachedResource(Object key, Object& resource, Boolean mustReturnDeferredResourceReference)
at System.Windows.SystemResources.FindResourceInternal(Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference)
at System.Windows.FrameworkElement.FindResourceInternal(FrameworkElement fe, FrameworkContentElement fce, DependencyProperty dp, Object resourceKey, Object unlinkedParent, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, DependencyObject boundaryElement, Boolean isImplicitStyleLookup, Object& source)
at System.Windows.FrameworkElement.FindResource(Object resourceKey)
at Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid.UpdateContainerHelper() in z:\Test\PropertyGridTest\ToolkitSrc\Main\Source\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\PropertyGrid\Implementation\PropertyGrid.cs:line 872
at Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid.EndInit() in z:\Test\PropertyGridTest\ToolkitSrc\Main\Source\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\PropertyGrid\Implementation\PropertyGrid.cs:line 1121
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
InnerException:
```
The root cause is the static readonly member "SelectedObjectAdvancedOptionsMenuKey", which is not properly initialized for every UI Thread. This is done just once, as it is static. Depending on which UI thread accesses this member, it may or may not fail.
I'll attach a demo project which demonstrates the issue.
Comments: ** Comment from web user: AndreasBa **
I tried to change the static readonly SelectedObjectAdvancedOptionsMenuKey to a normal member, but I still get the same exception when this.FindResource(...) is called.