In my App.xaml I have a few implicit styles
<Style TargetType="{x:Type Button}">
...Blah...
</Style>
These styles work for control as long as they are not in a custom control I create.
My Control
public class NavigationControl : Control
{
public static readonly DependencyProperty ButtonStyleProperty =
DependencyProperty.Register("ButtonStyle", typeof(Style), typeof(NavigationControl));
public Style ButtonStyle
{
get { return (Style)GetValue(ButtonStyleProperty); }
set { SetValue(ButtonStyleProperty, value); }
}
}
static NavigationControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NavigationControl), new FrameworkPropertyMetadata(typeof(NavigationControl)));
}
public NavigationControl()
{
}
My Control Styles and Templates
<ControlTemplate x:Key="NavigationControlTemplate" TargetType="{x:Type controls:NavigationControl}">
<Button Style="{TemplateBinding ButtonStyle}"
</ControlTemplate>
<Style x:Key="DefaultButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="MinWidth" Value="75"/>
<Setter Property="Height" Value="50"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Margin" Value="-1"/>
</Style>
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
<Setter Property="Template" Value="{StaticResource NavigationButtonTemplate}"/>
</Style>
<Style TargetType="{x:Type controls:NavigationControl}">
<Setter Property="Template" Value="{StaticResource NavigationControlTemplate}"/>
<Setter Property="ButtonStyle" Value="{StaticResource ButtonStyle}"/>
</Style>
Now I would assume that the DefaultButtonStyle's BasedOn would get it from the App level. But it doesnt. The only way to apply the app level style is Override the ButtonStyle by creating a style of type NavigationControl.
Is there a way where the implicit style makes this work?