==== Context Switching And Templates ====
<tabs><tab name="==== '''DataTemplate (Xamarin only)">''' =====
As described in the previous section, DataTemplates are designed to be used as templates for data contexts, therefore the content control used to render them, controls:ContentControl, has the TemplateContext property which allows you to set the binding context '''for the template'''. The important difference to note is that the controls:ContentControl itself will not use the TemplateContext, but rather the inherited context from its hosting xaml.
Because they are independent of each other, it allows more sophisticated usage of binding contexts, for example, when ''Object A'' has ''Status B'', show ''Property C''.
<tabs>
<tab name="UWP">
<source lang = "xml">
<ContentControl (displayed on child area of Object A)
Visibility="{Binding Values[STATUS], Converter={StaticResource EqualToVisConverter}, ConverterParameter=B}"
Content="{Binding PropertyItems[PROPERTYC]}"
ContentTemplate="{StaticResource MyPropertyTemplate}" />
</source>
</tab>
<tab name="Xamarin">
<source lang = "xml">
Xamarin:
<controls:ContentControl (displayed on child area of Object A)
IsVisible="{Binding Values[STATUS], Converter={StaticResource EqualityToBool}, ConverterParameter=B}"
</source>
</tab>
</tabs>
<tab name="==== '''ControlTemplate (Xamarin)">''' =====On the other hand, since the ControlTemplate is not designed to be used this way, it has no inherent binding context attribute that can be assigned to it's content only. The only benefit of using a ControlTemplate over a DataTemplate is the possibility to nest dynamic content (that has not been defined in the original ControlTemplate) within in, by use of the <nowiki><ContentPresenter... /></nowiki> attribute. To use it this way would therefore require a context switch on the ContentView used to render it, with the related adjustments required to bindings placed on the ContentView itself; <tabs><tab name="UWP">No example yet.</tab> <tab name="Xamarin">
<source lang = "xml">
Xamarin:
<ContentView (displayed on child area of Object A)
BindingContext="{Binding PropertyItems[PROPERTYC]}"
ControlTemplate="{StaticResource MyOtherPropertyTemplate}" />
</source>
{{Hint|CallingViewModel (as used on the IsVisible attribute) can be added to a metaproperty's binding path to bind to its context object.}}
</tab>
<tab name="ControlTemplate (Xamarin)">
No example yet.
</tab>
</tabs>
{{Attention|Remember that Styling in Xaml is type-based, so you cannot use the same template with controls:ContentControl (ContentTemplate attribute) and ContentView (ControlTemplate attribute), as DataTemplate and ControlTemplate are technically different types.}}
{{Hint|CallingViewModel (as used on the IsVisible attribute) can be added to a metaproperty's binding path to bind to its context object.}}
{{UnderConstructionEndAttention|Remember that Styling in Xaml is type-based, so you cannot use the same template with controls:ContentControl (ContentTemplate attribute) and ContentView (ControlTemplate attribute), as DataTemplate and ControlTemplate are technically different types.}}
{{UnderConstructionEnd}}
[[Category:Pages with broken file links|XAML Best practices]]
[[Category:XAML|XAML Best practices]]
== Performance ==