How can I customize the filtering row to allow just a custom control?
e.g. If I wanted to drop my own completely custom control into the filter row section (and I will handle the actual filtering my self, under the intention that I am just binding some text boxes to my view model and that it is handling the filtering of the item source)
The overall goal I want to achieve is to replace the existing filter row, with just a text box (with no operators control) so I can bind those to the view model to filter my items source (via async queries to web services)
---
I tried creating a derived class of the GridViewDataColumn where I expose a FilterEditor property. However, the issue I have with this approach is that:
1) I can not hide the filter operators (I have tried ShowFilterButton="False" ShowFieldFilters="False" ShowDistinctFilters="False" to no avail)
2) It takes 4 tabs to move between columns, and Ideally it should tab across directly. (As far as I can tell, the first table puts it into the filter operator, the second puts it into the drop down of the filter operators drop down, the third tab I have no idea where, and then finally the 4th moves the control to another column)
3) As mentioned in a previous post, the title does not shrink back down when the column header (or filter row) expands then shrinks (e.g. by typing in text, then removing it)
below is the code I used to create my custom column. (The FilterEditor content that I create is simply a textbox bound to my VM)
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Data;
using
Telerik.Windows.Controls;
public
class
CustomFilterGridViewDataColumn : GridViewDataColumn
{
public
static
readonly
DependencyProperty FilterEditorProperty =
DependencyProperty.Register(
"FilterEditor"
,
typeof
(UIElement),
typeof
(CustomFilterGridViewDataColumn),
new
PropertyMetadata(OnFilterEditorChanged));
private
static
void
OnFilterEditorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var me = (CustomFilterGridViewDataColumn)d;
if
(me._filterContainer ==
null
)
return
;
var uiElement = e.NewValue
as
UIElement;
me._filterContainer.Content =
null
;
if
(uiElement !=
null
) me._filterContainer.Content = uiElement;
}
private
ContentControl _filterContainer;
public
UIElement FilterEditor
{
get
{
return
(UIElement)GetValue(FilterEditorProperty); }
set
{ SetValue(FilterEditorProperty, value); }
}
public
override
FrameworkElement CreateFieldFilterEditor()
{
_filterContainer =
new
ContentControl();
if
(FilterEditor !=
null
) _filterContainer.Content = FilterEditor;
Binding binding =
new
Binding();
binding.Source =
this
.DataControl;
binding.Path =
new
PropertyPath(FrameworkElement.DataContextProperty);
binding.Mode = BindingMode.OneWay;
BindingOperations.SetBinding(_filterContainer, FrameworkElement.DataContextProperty, binding);
return
_filterContainer;
}
}