I am binding the height of a CustomControl (Let's call it MyButton
) to an inheritable attached property inside the style of the CustomControl:
<Setter Property="Height" Value="{Binding (local:Element.IconContainerSize), RelativeSource={RelativeSource Self}}"/>
However, this doesn't work both in the designer and when I run it. This happens only when I set the Bindings inside the style of the CustomControl. When I set the bindings inside the resources of its container or explicitly set it to its Height when declared, it works:
<StackPanel my:Element.IconContainerSize="18">
<StackPanel.Resources>
<Style TargetType="{x:Type cc:MyButton}">
<!-- Works -->
<Setter Property="Height" Value="{Binding (my:Element.IconContainerSize), RelativeSource={RelativeSource Self}}"/>
</style>
</StackPanel.Resources>
<!-- Also works -->
<cc:MyButton Height="{Binding (my:Element.IconContainerSize), RelativeSource={RelativeSource Self}}"/>
<!-- Doesn't work (assuming the style above is removed in this case) -->
<cc:MyButton />
</StackPanel>
UPDATE: Adding a Path=
before the attached property path works only at runtime and not at design time until I manually reload the solution. I can't manage to make it work during Design time right after I rebuild the project for the CustomControl library when I edit something in the project.