PropertyGrid cannot seem to be used from a worker UI thread

Grids for WPF Forum

Posted 14 years ago by wpf.acp
Version: 9.1.0505
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
I have been experimenting with ribbon, ribbon window and docking features in a worker thread and this all worked without a single issue. Then I have tried adding a simple PropertyGrid to this window and I got the following exception:

'TreeListViewRowPresenter' object cannot be added to 'Border'. Exception has been thrown by the target of an invocation. Error at object 'ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.TreeListViewRowPresenter' in markup file 'ActiproSoftware.PropertyGrid.Wpf30;component/Themes/PropertyGrid/Common.xaml'.

I have created a sample that reproduces the issue. The sample uses the very button as SelectedObject but it really doesn't matter which object is used or even if PropertyGridPropertyItem is used instead.
    public partial class Window1
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void _button_OnClick(object sender, RoutedEventArgs e)
        {
            var thread = new Thread(WorkerThread);
            thread.TrySetApartmentState(ApartmentState.STA);
            thread.Start();
        }

        private static void WorkerThread(object obj)
        {
            var win = new Window1();
            win.ShowDialog();
        }
    }
<Window x:Class="PropertyGridThreadBug.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:PropertyGrid="clr-namespace:ActiproSoftware.Windows.Controls.PropertyGrid;assembly=ActiproSoftware.PropertyGrid.Wpf30"
    Title="Window1" Height="300" Width="300">

    <DockPanel>
        <Button x:Name="_button"
                DockPanel.Dock="Bottom"
                Click="_button_OnClick">
            Create Worker Thread
        </Button>
        <PropertyGrid:PropertyGrid SelectedObject="{Binding ElementName=_button}" />
    </DockPanel>
</Window>

Comments (3)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

We tried your sample and did not see any issue. If you can please email over a sample project to our support address, then we can take another look. There may be a setting you have set on the project that we do not.

Also, if you can provide a more detailed stack trace from the resulting exception, then that may help.


Actipro Software Support

Posted 14 years ago by wpf.acp
Avatar
For reproduction I just created a vanilla WPF project and put together the code I previously posted. I have sent the full project to your support email.

Please find the detailed stack trace below.
System.Windows.Markup.XamlParseException occurred
  Message="'TreeListViewRowPresenter' object cannot be added to 'Border'. Exception has been thrown by the target of an invocation.  Error at object 'ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.TreeListViewRowPresenter' in markup file 'ActiproSoftware.PropertyGrid.Wpf30;component/Themes/PropertyGrid/Common.xaml'."
  Source="PresentationFramework"
  LineNumber=0
  LinePosition=0
  NameContext="PART_Header"
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
  InnerException: System.Reflection.TargetInvocationException
       Message="Exception has been thrown by the target of an invocation."
       Source="mscorlib"
       StackTrace:
            at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
            at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
            at System.Windows.Markup.XamlTypeMapper.SetInternalPropertyValue(ParserContext pc, Object rootElement, PropertyInfo pi, Object target, Object value)
            at System.Windows.Markup.BamlRecordReader.AddToContentProperty(Object container, Object contentProperty, Object value)
       InnerException: System.ArgumentException
            Message="Must create DependencySource on same Thread as the DependencyObject."
            Source="WindowsBase"
            StackTrace:
                 at System.Windows.DependencyObject.ValidateSources(DependencyObject d, DependencySource[] newSources, Expression expr)
                 at System.Windows.Expression.ChangeSources(DependencyObject d, DependencyProperty dp, DependencySource[] newSources)
                 at System.Windows.Data.BindingExpressionBase.ChangeSources(DependencyObject target, DependencyProperty dp, WeakDependencySource[] newSources)
                 at System.Windows.Data.BindingExpressionBase.ChangeSources(WeakDependencySource[] newSources)
                 at System.Windows.Data.BindingExpression.ChangeWorkerSources(WeakDependencySource[] newWorkerSources, Int32 n)
                 at MS.Internal.Data.ClrBindingWorker.ReplaceDependencySources()
                 at MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
                 at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
                 at MS.Internal.Data.PropertyPathWorker.AttachToRootItem(Object rootItem)
                 at MS.Internal.Data.ClrBindingWorker.AttachDataItem()
                 at System.Windows.Data.BindingExpression.Activate(Object item)
                 at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
                 at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
                 at System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp)
                 at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
                 at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
                 at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
                 at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
                 at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, BindingBase binding)
                 at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.TreeListViewRowPresenter.CreateCell(TreeListViewColumn column)
                 at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.TreeListViewRowPresenter.UpdateItems()
                 at ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.TreeListViewRowPresenterBase.a(DependencyObject A_0, DependencyPropertyChangedEventArgs A_1)
                 at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
                 at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
                 at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
                 at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
                 at System.Windows.TreeWalkHelper.InvalidateTreeDependentProperty(TreeChangeInfo info, DependencyObject d, FrameworkObject& fo, DependencyProperty dp, FrameworkPropertyMetadata fMetadata, Style selfStyle, Style selfThemeStyle, ChildRecord& childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent)
                 at System.Windows.TreeWalkHelper.InvalidateTreeDependentProperties(TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ChildRecord& childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent)
                 at System.Windows.FrameworkElement.InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, Boolean isSelfInheritanceParent)
                 at System.Windows.FrameworkElement.OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
                 at System.Windows.TreeWalkHelper.OnAncestorChanged(FrameworkElement fe, FrameworkContentElement fce, TreeChangeInfo info)
                 at System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
                 at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
                 at MS.Internal.FrameworkObject.ChangeLogicalParent(DependencyObject newParent)
                 at System.Windows.FrameworkElement.AddLogicalChild(Object child)
                 at System.Windows.Controls.Decorator.set_Child(UIElement value)
            InnerException: 
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Thanks for the report, I was able to reproduce this issue with the 505 build (the current release). This appears to be fixed in our current development build. I believe there was an issue with the "shared" column information, which was resolved per this post.

So this will be resolved in the next maintenance release.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.