WPF - Can only base on a Style with target type that is base type

Viewed 1364

This is sending me nuts, mostly because at runtime it works perfectly (the problem only appear at design time), but I decided to ask anyway as I'm working on a big project and I want to implement things the best way.

First thing: I have a component from a third part library, it is basically like a border, and it's defined this way (with F12):

public class AdvancedBorder : ContentControl

I like the visual aspect of this thing, but I need to add some functionalities. So I created a new Custom 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 the exactly same visual but adding 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 the xmlns for my namespace, otherLibrary is the xmlns for the third part library.

Everything works perfectly fine at runtime, and gives no errors at all. At design time I get no errors from the generic.xaml, but as soon as I put the SelectableCard in some xaml file, I get

Can only base on a Style with target type that is base type SelectableCard

And I don't get it at all, especially as it works at runtime. I can remove the BasedOn attribute and I get no more complaints at design time, but then I have to add the setter for the template otherwise I can't see anything at runtime.

What am I doing wrong, here?

0 Answers
Related