I have defined following in a ResourceDictionary:
<DockPanel x:Key="errorDisplay" LastChildFill="False">
<Border Background="Red" DockPanel.Dock="Top">
<TextBlock x:Name="errorTextBlock" />
</Border>
<Canvas DockPanel.Dock="Top" Height="15">
<Polygon
Points="{Binding ElementName=errorDisplay, Path=ActualWidth, Converter={StaticResource PointsToStringArrayConverter},Mode=OneWay}"
Fill="Red" Stroke="Black" StrokeThickness="1" />
</Canvas>
</DockPanel>
This resource is added to an adorner layer in code behind on loading of a usercontrol.
However, I get a binding error
(Cannot find source for binding with reference
‘ElementName=errorDisplay’)
. I am aware of namescopes, but surely the above should work as it all takes place within the single composite control, with the same namescope applying?
EDIT (Using RelativeSource/AncestorType instead of elementname does not seem to work either.) Does work! But actualwidth is Nil
EDIT: using ElementName=errorTextBlock also results in same binding error!
You haven’t named the DockPanel you have provided a resource key.
Try
<DockPanel x:Key="errorDisplay" x:Name="errorDisplay" LastChildFill="False">However as you say, this doesn’t work when tested.
A relative source binding seems to work in this cut down version of your code though:
This is in a resource element
and I’m using it like this: