I am trying to make short version of my binding markup by creating class inherited from Binding and setting all properties in constructor. This is simplified version of how original markup looks like (works as intended):
<Setter Property="Text" Value="{Binding Title, RelativeSource={RelativeSource AncestorType=Window}}"/>
I have tried making this expression shorter by creating this class:
public class TitleExtension : Binding
{
public TitleExtension()
{
Path = new PropertyPath("Title");
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Window), 1);
}
}
And using it like this:
<Setter Property="Text" Value="{p:Title}"/>
This works in runtime but doesn't in design-time. But if I add RelativeSource markup to my expression, then it works fine in design-time and runtime. Like this:
<Setter Property="Text" Value="{p:Title, RelativeSource={RelativeSource AncestorType=Window}}"/>
I will be glad to hear all your explanations of this behavior, as well as the proposed solutions. Thanks!