When using traditional {Binding} syntax you could specify element name to point to a specific control on the page, and be able to access its properties. For example if the page is named page
you could do:
{Binding ElementName=Page, Path=Name}
With the {x:Bind} syntax it says
With x:Bind, you do not need to use ElementName=xxx as part of the binding expression. With x:Bind, you can use the name of the element as the first part of the path for the binding because named elements become fields within the page or user control that represents the root binding source.
So for the example above in {x:Bind} would be
{x:Bind page.Name}
Which works fine, until it is inside a data template (for example a ListView's ItemTemplate). In which case it no longer works as it is looking for Page
on the data type specified which leads to the following error (assuming my data type is customer
):
XamlCompiler error WMC1110: Invalid binding path 'Page.Name' : Property 'Page' can't be found on type 'Customer'
What is the solution to use {x:Bind} syntax with datatemplates and access controls outside the data template?
Example code is available here (note specific commit)
page
definition inCustomer
. – Offer