Sunday, March 14, 2010

How to suppress the System.Windows.Data Error warning message

Hi,

When we use FindAncesstor in custom control template for binding internal elements property into its ancestor element, visual studio displays data warning messages in output window when binding engine meets unmatched target type during visual tree traversal though it does the proper binding when it receives expected target type during visual tree traversal. To suppress this data error warning messages, you should mention level of warning message trace in your library class.

Here is the simple data error that I am getting when I bind some commands in rich text box.

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.RichTextBox', AncestorLevel='1''. BindingExpression:Path=Content; DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.RichTextBox', AncestorLevel='1''. BindingExpression:Path=Content; DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.RichTextBox', AncestorLevel='1''. BindingExpression:Path=Content; DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.RichTextBox', AncestorLevel='1''. BindingExpression:Path=Content; DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.RichTextBox', AncestorLevel='1''. BindingExpression:Path=Content; DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.RichTextBox', AncestorLevel='1''. BindingExpression:Path=Content; DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')

Solution, set data binding source switch level as critical in constructor of the class.

System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;

Thanks,
Venugopal.

No comments:

Post a Comment