Details
-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
2.5
-
None
Description
Elements added as children of a ContentControl, e.g. Button, in xaml are not registered in the correct namescope if the ContentControl's ContentPresenter is contained in a Template.
The child elements get registered in the ContentControl's namescope but end up being displayed as children of the ContentPresenter, which has it's own namescope if it is contained in a template. Any references to named elements in the content, e.g. binding to an element name, end up looking in the ContentPresenter's namescope and not the ContentControl's namescope and therefore do not find the elements.
Example of broken behaviour:
<Button>
<Button.Template>
<ControlTemplate>
<ContentPresenter />
</ControlTemplate>
</Button.Template>
<Label x:Name="NamedLabel" />
<!--
This binding will not work because NamedLabel is registered in the same namescope as the Button,
but ends up being displayed as a child of the ContentPresenter above which has a separate namescope because
it is contained in it's own template. Any bindings will look in the ContentPresenter's namescope and not the
button's namescope.
-->
<Label IsVisible="{Binding ElementName=NamedLabel, Path=IsVisible}" />
</Button>
The child elements get registered in the ContentControl's namescope but end up being displayed as children of the ContentPresenter, which has it's own namescope if it is contained in a template. Any references to named elements in the content, e.g. binding to an element name, end up looking in the ContentPresenter's namescope and not the ContentControl's namescope and therefore do not find the elements.
Example of broken behaviour:
<Button>
<Button.Template>
<ControlTemplate>
<ContentPresenter />
</ControlTemplate>
</Button.Template>
<Label x:Name="NamedLabel" />
<!--
This binding will not work because NamedLabel is registered in the same namescope as the Button,
but ends up being displayed as a child of the ContentPresenter above which has a separate namescope because
it is contained in it's own template. Any bindings will look in the ContentPresenter's namescope and not the
button's namescope.
-->
<Label IsVisible="{Binding ElementName=NamedLabel, Path=IsVisible}" />
</Button>