I found a way to do what I wanted, not sure if it's the best way though. Here is what I ended up doing:
I made a custom control that will be used in the
DataGridColumnHeader
as a filter control. This control has the following properties:
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register("Filter", typeof(eFilterType), typeof(FilterControl),new PropertyMetadata((eFilterType)(-1)));
public eFilterType Filter
{
get { return (eFilterType)GetValue(FilterProperty); }
set { SetValue(FilterProperty, value); }
}
public static readonly DependencyProperty ColumnProperty = DependencyProperty.Register("Column", typeof(DataGridColumn), typeof(FilterControl), new PropertyMetadata(null,new PropertyChangedCallback(ColumnChanged)));
public DataGridColumn Column
{
get { return (DataGridColumn)GetValue(ColumnProperty); }
set { SetValue(ColumnProperty, value); }
}
public static readonly DependencyProperty FilterTypeProperty = DependencyProperty.RegisterAttached("FilterType", typeof(eFilterType), typeof(FilterControl), new PropertyMetadata((eFilterType)(-1)));
public static eFilterType GetFilterType(DataGridColumn Column)
{
return (eFilterType)Column.GetValue(FilterTypeProperty);
}
public static void SetFilterType(DataGridColumn Column,eFilterType Type)
{
Column.SetValue(FilterTypeProperty, Type);
}
The control has a callback when the Column property changes, it then sets the
FilterProperty
for the control
public static void ColumnChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is DataGridColumn)
{
DataGridColumn Col = (DataGridColumn)e.NewValue;
eFilterType Type = (eFilterType)Col.GetValue(FilterTypeProperty);
o.SetValue(FilterProperty, Type);
}
}
In the Generic.xaml I bound the Column property to the DataGridHeader's Column property like this:
<local:filtercontrol column="{Binding <br mode=" hold=" /> RelativeSource={RelativeSource <br mode=" xmlns:local="#unknown"></local:filtercontrol>
All this enables me to use a Trigger from the FilterControl's template like this:
<controltemplate.triggers>
<trigger property="Filter" value="BoolFilter">
<setter property="Background" value="Red">
TargetName="tbText"/>
</setter></trigger></controltemplate.triggers>
That is what I have currently, please let me know if there is a better way.