private void FilterString(string propName, string[] values) { var removeItems = new List <object>(); foreach (var item in Items) { if (values.FirstOrDefault( p => ((string)RowType.GetProperty(propName).GetValue(item))?.Contains(p) ?? false) == null) { removeItems.Add(item); } } removeItems.ForEach(p => Items.Remove(p)); }
protected override void ApplyDynamicColumns(DependencyPropertyChangedEventArgs e) { if (!(e.NewValue is DataGridCloumnsCollection newColumns)) { return; } Columns.Clear(); colTypes.Clear(); fstringModels.Clear(); fzModels.Clear(); fdModels.Clear(); foreach (var col in newColumns) { if (RowType == null) { Columns.Add(col); continue; } if (!(col is DataGridTextColumn textColumn)) { Columns.Add(col); continue; } if (!(textColumn.Binding is Binding colBinding)) { Columns.Add(col); continue; } if (colBinding.Path == null) { Columns.Add(col); continue; } var prop = RowType.GetProperty(colBinding.Path.Path); if (prop == null) { Columns.Add(col); continue; } //当前仅支持三种类型的过滤; if (prop.PropertyType == typeof(DateTime?) || prop.PropertyType == typeof(string) || prop.PropertyType == typeof(long) ) { if (!(col.Header is string headerText)) { Columns.Add(col); continue; } var headerControl = new FilterHeader { PropertyType = prop.PropertyType, PropertyName = prop.Name }; headerControl.FilterRequired += OnFilterRequired; if (prop != null) { colTypes.Add(prop.Name, prop.PropertyType); } if (prop.PropertyType == typeof(string)) { fstringModels.Add(prop.Name, null); } col.Header = headerControl; } Columns.Add(col); } }