I remember reading a couple of weeks ago that it sometimes doesn't work inside templates, and I recently tried to bind things in two different windows and it couldn't find the name declarations, so I assumed that it was local to the namespace of the class and just bound by setting the datacontext instead. However, I'm really curious when I am able to use binding elementname and when I cannot, because it's far more convenient when it is possible.
edit: In reading that article, I found this to be interesting:
"For this reason, styles and templates both define their own XAML namescopes, independent of whatever location in an object tree where the style or template is applied."
if this is true, doesn't that mean that Binding ElementName should not work in templates at all? But then I definitely have some working bindings on ElementName within my templates. That is the most confusing part, why do some bindings randomly work inside the templates and others do not? It must have some method for trying to resolve the name even if it isn't in the template or same namescope
ElementName
binding only works for elements in the same NameScope – Federico BerasateguiNamespace
, not aNamescope
. Those are 2 different concepts.Namespace
is anXML
concept, andNamescope
is a XAML concept. – Federico BerasateguiElementName
binding does not work if it is defined inside aDataTemplate
and points to a UI ElementOutside
thatDataTemplate
. If you have a working one, please post the XAML. – Federico Berasategui