I'm trying to create a custom user control. I've created ResourceDictionary file (Themes\Generic.xaml) with two styles:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
xmlns:components="clr-namespace:ORPO.WPF.Components">
<Style TargetType="{x:Type components:HeaderFilterDataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
...
</Style>
<Style TargetType="{x:Type DataGridColumnHeader}">
...
</Style>
</ResourceDictionary>
and my custom control class:
public class HeaderFilterDataGrid : DataGrid
{
...
static HeaderFilterDataGrid()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeaderFilterDataGrid),
new FrameworkPropertyMetadata(typeof(HeaderFilterDataGrid)));
}
...
}
It works fine when I apply first style
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeaderFilterDataGrid),
new FrameworkPropertyMetadata(typeof(HeaderFilterDataGrid)));
How can i apply second style for my custom control? I need both styles to be applied at the same time.
Put the DataGridColumnHeader Style in the Resources of the HeaderFilterDataGrid Style. This way DataGridColumnHeader will be a default style for all DataGridColumnHeaders in a HeaderFilterDataGrid.
<ResourceDictionary ...>
<Style TargetType="{x:Type components:HeaderFilterDataGrid}"
BasedOn="{StaticResource {x:Type DataGrid}}">
<Style.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
...
</Style>
</Style.Resources>
...
</Style>
</ResourceDictionary>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With