Let's say I have a base viewmodel for a specific control that implements some basic properties, e.g.
public abstract class ControlVmBase{
public abstract int IconSize {get;set;}
}
I also have a ResourceDictionary which I want to use with that control, and ideally bind values in the contained styles to an implementation of ControlVmBase
. I thought it would be a good idea to do this via an ObjectDataProvider, since it looks like a clean solution and gives me Intellisense support in the XAML:
<ResourceDictionary>
<ObjectDataProvider x:Key="LinkedVm" ObjectType="{x:Type ControlVmBase}" />
<Style x:Key="MySpecialControlStyle" TargetType="MyCustomControl">
<Setter Property="ImageSize" Value="{Binding Source={StaticResource LinkedVm}, Path=IconSize}" />
</Style>
</ResourceDictionary>
However this doesn't work, since the ODP tries to instantiate ObjectType which is pointless, since it's an abstract class an doesn't affect the implemented classes. Is it possible to use an ODP like that, or is there another possibility to bind to derived classes?