I'm building a custom control search box in wpf based on the common windows search bar (my version). In the windows implementation the buttons would change background and foreground depending on whether they were pressed or not. To do this I'm using a style and triggers to change the button colors.
As I'm using MaterialDesign my custom control contains a button which uses the derived/default material design button. When a style is applied to this button the material design style is overridden in favor for the default wpf button. How can I apply a style while keeping the base material design style?
As my issue is solely with applying a style to a button I have omitted the search box style and instead created an example of my problem containing just a button.
Generic.xaml -CustomButton
<Style TargetType="{x:Type local:CustomButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomButton}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<!-- Normally the below button would be inside a grid with additional buttons, labels and content presenter. I have removed these for simplicity-->
<Button Name="MaterialButton"
Content="CustomButton">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
App.xaml - (Material Design is in resource dictionary.)
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
What I've tried
I've tried using the BasedOn attribute as suggested here and here however this has not resolved my issue.
Deriving from a material style based on the "Material Design theme is lost" FAQ, results in this error: Exception: Cannot find resource named 'MaterialDesignFlatButton'. Resource names are case sensitive.
Generic.Xaml Attempted changes to CustomButton
<!--Same custon control as before--->
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignFlatButton}">
<!--same trigger-->