Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How do I know if Binding RelativeSource found an ancestor

I'm using the binding RelativeSource with the FindAncestor Mode but the binding is not working. How do I debug and see if It is able to find the ancestor?

like image 308
Aks Avatar asked Mar 03 '11 10:03

Aks


People also ask

How do I find my ancestor level in WPF?

How do I determine the AncestorLevel? By looking at the visual tree and figuring out the number of occurances of a specific type of parent element.

What is binding RelativeSource?

The 'RelativeSource' property of the Binding class is used to bind the data from an element by it's relationship to the source element. RelativeSource is also a markup extension of type RelativeSource.

What is binding path in WPF?

Binding path syntax. Use the Path property to specify the source value you want to bind to: In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as Path=PropertyName . Subproperties of a property can be specified by a similar syntax as in C#.

What is DataContext in WPF?

The DataContext property is the default source of your bindings, unless you specifically declare another source, like we did in the previous chapter with the ElementName property. It's defined on the FrameworkElement class, which most UI controls, including the WPF Window, inherits from.


3 Answers

use Snoop

EDIT: you can of course use the usual debugging mechanisms, but I like Snoop the best. You can navigate to your control and if your binding failed it tells you so

like image 74
Markus Hütter Avatar answered Nov 04 '22 06:11

Markus Hütter


Or you can set PresentationTraceSources.TraceLevel on the binding. If you are using VS2010 remember to set the Data binding value in Options->Debugging->Output Window

like image 37
Krimson Avatar answered Nov 04 '22 04:11

Krimson


I use WPF Inspector, it's a nice free tools for debugging WPF application in XAML level.

like image 1
Jacob Avatar answered Nov 04 '22 06:11

Jacob