Hi,
Nice article for this requirement.
http://www.julmar.com/blog/mark/2008/09/12/Part3ShiftingFocusToTheFirstAvailableElementInWPF.aspx
-Venugopal.
Right place to discuss about Silverlight and WPF. Lets join with me to share more information about this amazing technology.
Thursday, March 18, 2010
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.
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.
Wednesday, March 10, 2010
Binding AttachedProperty Based on SelectedItem in Xaml
Hi,
Today one of our WPF product customer raised a question about how to bind an attached property in XAML. I was wondered like what is the problem in it, and I just replied him immediately with below code.
But after his detailed reply for my post, came to know that his question was valid :). Because he wants to bind the attached property of custom ItemsControl using its items object without mentioning specific child object name whenever active item gets changed.
I just tried following code and its working perfectly without any event handler or converter in View Modal application.
Here is the solution.
Note that, ActiveItem should get updated whenever you select any item in itemscontrol. Just like SelectedItem property.
Thanks to the WPF team for providing powerful binding stuffs.
-Venugopal.
Today one of our WPF product customer raised a question about how to bind an attached property in XAML. I was wondered like what is the problem in it, and I just replied him immediately with below code.
But after his detailed reply for my post, came to know that his question was valid :). Because he wants to bind the attached property of custom ItemsControl using its items object without mentioning specific child object name whenever active item gets changed.
I just tried following code and its working perfectly without any event handler or converter in View Modal application.
Here is the solution.
Note that, ActiveItem should get updated whenever you select any item in itemscontrol. Just like SelectedItem property.
Thanks to the WPF team for providing powerful binding stuffs.
-Venugopal.
Subscribe to:
Posts (Atom)