Page 1 of 1

Solidworks Addin System.Windows.Data Error: 4

Posted: Mon May 17, 2021 2:39 am
by Max Han
Here occurs a error when I debug the AddIn, the error is like this:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='up_tol0'); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='up_tol0'); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='dn_tol0'); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='dn_tol0'); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='up_tol0_Sec'); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='up_tol0_Sec'); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='dn_tol0_Sec'); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name='dn_tol0_Sec'); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')
It' seems about binding error of Combox component, but strange thing is that it happens on the first time I open a drawing, It's should not call any method to show or create the UI element, because I haven't click any button or initial any UI elements. I tried that if I open a model first rather than a drawing, that error would not occur.
I have tried remove all the combox tool in the WPF UI, but it still happens... From the error we got that the combox "Name='up_tol0'", this kind of name seems not my customized toolbox.
There is a old question is about the same questions, even the same name, is this a bug about soldiworks ?
>>>https://forum.solidworks.com/thread/65185

What's more, my addin if from SW template, and I create some WPF windows in it, after click the button in the Tab then the WPF window shown. Some time in using, the window freezing, I close the window, then I open the window again, the window would be blank window, till I restart solidworks it goes normal. I'm not sure about if it's caused by the above error.

Re: Solidworks Addin System.Windows.Data Error: 4

Posted: Mon May 17, 2021 8:27 am
by AlexB
I get the same error with some of my controls but it appears to be a WPF thing. The following link might help, but the errors are "harmless" according to a few sources I am finding.

https://weblogs.asp.net/akjoshi/resolvi ... ors-in-wpf

Re: Solidworks Addin System.Windows.Data Error: 4

Posted: Mon May 17, 2021 11:15 am
by Max Han
AlexB wrote: Mon May 17, 2021 8:27 am I get the same error with some of my controls but it appears to be a WPF thing. The following link might help, but the errors are "harmless" according to a few sources I am finding.

https://weblogs.asp.net/akjoshi/resolvi ... ors-in-wpf
Hi AlexB,
So much thanks to your post, I tried to set the default H (HorizontalContentAlignment) and Vz9VerticalContentAlignment) property in my dictionary xaml, but it doesn't work for me, and I even have set every combox with property H and V, and the error is still there o[ May I have to persuade myself to adopt it, as it's no affect much.