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?
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.
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.
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#.
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.
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
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
I use WPF Inspector, it's a nice free tools for debugging WPF application in XAML level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With