Are these equivalent or is there a difference?
Color="{ReadProperty BackgroundColor}"
Color="{ReadProperty this.BackgroundColor}"
Are these equivalent or is there a difference?
Color="{ReadProperty BackgroundColor}"
Color="{ReadProperty this.BackgroundColor}"
The answer is “yes, but there’s more to it”.
If you have not assigned an explicit ux:Name
to your ux:Class
:
<Panel ux:Class="CustomComponent">
<string ux:Property="SomeProperty" />
<StackPanel>
<Text Value="{ReadProperty SomeProperty}" />
<Text Value="{ReadProperty this.SomeProperty}" />
</StackPanel>
</Panel>
Then those two are equivalent, because this
is the implicit ux:Name
assigned to a ux:Class
when there is not an explicit ux:Name
set.
However, if you assign an explicit ux:Name
to a ux:Class
, you HAVE TO prefix properties with that ux:Name
you gave the class, because in this case this
refers to the first ux:Class
ancestor without an explicit ux:Name
:
<Panel ux:Class="CustomComponent" ux:Name="cc">
<string ux:Property="SomeProperty" />
<Text Value="{ReadProperty cc.SomeProperty}" />
</Panel>
Omitting the prefix, or using this
in this case will result in an error, because the ancestor does not have that property defined on it, and you can’t directly access it from the data scope you’re in (from within the ux:Class
).
If you’re wondering why you’d assign a ux:Name
to a ux:Class
, that’s because sometimes you need to avoid obscurity that using this
brings. Those are quite complex scenarios, so you probably won’t encounter one soon, and I’d suggest to avoid creating such constructs altogether.
Hope this helps!