this.dataGrid.FilterItemsPopulating += DataGrid_FilterItemsPopulating;
private void OnDataGrid_FilterItemsPopulating(object sender, GridFilterItemsPopulatingEventArgs e)
{
var filterControl = e.FilterControl;
CheckboxFilterControl checkBoxFilterControl = (CheckboxFilterControl)filterControl.GetType().GetField("CheckboxFilterControl", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(filterControl);
checkBoxFilterControl.Loaded += OnCheckBoxFilterControl_Loaded;
}
void OnCheckBoxFilterControl_Loaded(object sender, RoutedEventArgs e)
{
CheckboxFilterControl checkBoxFilterControl = sender as CheckboxFilterControl;
TextBox searchTextBox = (TextBox)checkBoxFilterControl.GetType().GetField("SearchTextBox", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(checkBoxFilterControl);
if (searchTextBox != null)
{
searchTextBox.PreviewTextInput += OnSearchTextBox_PreviewTextInput;
}
}
private void OnSearchTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !IsTextAllowed(e.Text, @"[^a-zA-Z]");
}
private static bool IsTextAllowed(string Text, string AllowedRegex)
{
try
{
var regex = new Regex(AllowedRegex);
return !regex.IsMatch(Text);
}
catch
{
return true;
}
}
|