20

Assembly A - ResourceDictionary contains StyleA style.
Assembly B - ResourceDictionary.MergedDictionaries to merge resources from Assembly A into B.

I would like to create a style in Assembly B "based on" StyleA. Is it possible?

I am trying to create this style:

<Style x:Key="StyleB" BasedOn="{StaticResource StyleA}">
   <Setter Property="Button.Foreground" Value="Khaki"/>
</Style>

But I get a XamlParseException exception at run-time, if I use StyleB:

Cannot convert the value in attribute 'Style' to object of type 'System.Windows.Style'. Can only base on a Style with target type that is base type 'IFrameworkInputElement'. Error at object 'System.Windows.Controls.Button' in markup file 'SamSeekApp;component/mainwindow.xaml'

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Gus Cavalcanti
  • 10,527
  • 23
  • 71
  • 104

1 Answers1

42

Try adding TargetType="{x:Type Button}" to your 'StyleB'.

Richard Davis
  • 496
  • 5
  • 2