WPF - can only be based on style with a target type which is the base type
This is sending me nuts, mostly because it works great while running (the problem only occurs during development), but I decided to ask anyway how am I working on a large project and I want to best implement things.
First, I have a component from the third part library, it is basically like a border, and it is defined this way (with F12):
public class AdvancedBorder : ContentControl
I love the visual aspect of this thing, but I need to add some functionality. So I created a new user control:
public class SelectableCard : AdvancedBorder
{
// bunch of custom properties and stuff
static SelectableCard()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SelectableCard), new FrameworkPropertyMetadata(typeof(SelectableCard)));
}
}
Finally, I need to keep exactly the same visibility, but add some triggers, so I put this in generic.xaml:
<Style TargetType="{x:Type customControls:SelectableCard}" BasedOn="{StaticResource ResourceKey={x:Type otherLibrary:AdvancedBorder}}">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Style.Triggers>
<Trigger Property="customControls:SelectableCard.IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource MyLightBrush}" />
</Trigger>
</Style.Triggers>
</Style>
customControls
is xmlns for my namespace, otherLibrary
is xmlns for third part library.
Everything works fine at runtime and doesn't give any errors. During development I get no errors with generic.xaml, but as soon as I put the SelectableCard in some xaml file I get
Can only be based on target type style, which is the base SelectableCard type
And I don't get it at all, especially since it works at runtime. I can remove the attribute BasedOn
and I don't get any more complaints during development, but then I need to add an installer for the template, otherwise I can't see anything at runtime.
What am I doing wrong, here?
source to share
No one has answered this question yet
Check out similar questions: