private void CbAllCheck_Click(object sender, RoutedEventArgs e) { IsDefaultSelectAll = true; foreach (var item in FilteredItemsSource) { AllSelectedPropertyChanged selectedModel = item as AllSelectedPropertyChanged; if (selectedModel == null) { continue; } if (AllChecked) { if (selectedModel.IsSelected != "1") { selectedModel.IsSelected = "1"; } } else { if (selectedModel.IsSelected != "0") { selectedModel.IsSelected = "0"; } } } if (CheckedSelectedChanged != null) { CheckedSelectedChanged(null, new CheckSelectedEventArgs(true)); } IsDefaultSelectAll = false; //if (this.Filters != null) // foreach (var filter in this.Filters) // filter.ResetControl(); }
private void cbDistinctProperties_DropDownOpened(object sender, EventArgs e) { if (_boundColumnPropertyAccessor != null) { if (FilterSelectedItem.BoolPropertyValues.Count == 0) { List <object> result = new List <object>(); foreach (var i in FilterSelectedItem.Grid.ItemsSource) { AllSelectedPropertyChanged selectedModel = i as AllSelectedPropertyChanged; object value = _boundColumnPropertyAccessor(selectedModel); if (value != null) { if (result.Where(o => o.ToString() == value.ToString()).Count() == 0) { result.Add(value); } } else if (FilterColumnInfo.PropertyType == typeof(bool?) && FilterColumnInfo.IsSpecialState) { if (result.Where(o => o == value).Count() == 0) { result.Add(value); } } } try { result.Sort(); } catch { if (System.Diagnostics.Debugger.IsLogging()) { System.Diagnostics.Debugger.Log(0, "Warning", "There is no default compare set for the object type"); } } foreach (var obj in result) { var item = new CheckboxComboItem() { Description = GetFormattedValue(obj), Tag = obj }; FilterSelectedItem.BoolPropertyValues.Add(item); } } } }
protected override void OnSelectionChanged(SelectionChangedEventArgs e) { base.OnSelectionChanged(e); if (this.CurrentCell.Column == null) { return; } if (this.CurrentCell.Column.Header is CheckBox) { if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) { foreach (var item in this.SelectedItems) { AllSelectedPropertyChanged selectedModel = item as AllSelectedPropertyChanged; CheckBox cb = (Mouse.DirectlyOver as UIElement) as CheckBox; if (cb == null || cb.DataContext != selectedModel) { selectedModel.IsSelected = "1"; } } } } }
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { base.OnPropertyChanged(e); if (e.Property.Name == "IsPositiveSequence") { this.CollectionView.SortDescriptions.Clear(); SortDescription sd = new SortDescription(); sd.PropertyName = SortPropertyName; if (IsPositiveSequence == true) { sd.Direction = ListSortDirection.Ascending; } else if (IsPositiveSequence == false) { sd.Direction = ListSortDirection.Descending; } this.CollectionView.SortDescriptions.Add(sd); ObservableCollection <AllSelectedPropertyChanged> list = new ObservableCollection <AllSelectedPropertyChanged>(); foreach (var item in CollectionView) { AllSelectedPropertyChanged selectedModel = item as AllSelectedPropertyChanged; //selectedModel.Num= count++; list.Add(selectedModel); } int count = 1; foreach (var item in list) { if (item == null) { continue; } item.Num = count++; } } }
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ColumnInfo info = cbColumns.SelectedItem as ColumnInfo; if (FilterSelectedItem.Grid.FilterType == null || info == null) { return; } FilterColumnInfo = new OptionColumnInfo(info.DataGridColumn, FilterSelectedItem.Grid); FilterSelectedItem.FilterOperations.Clear(); if (FilterColumnInfo.PropertyType != null) { if (FilterColumnInfo.PropertyConvertType != null) { if (TypeHelper.IsStringType(FilterColumnInfo.PropertyConvertType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "等于", "/Jib.WPF.Controls;component/Images/Equal.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "包含", "/Jib.WPF.Controls;component/Images/Contains.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "开始于", "/Jib.WPF.Controls;component/Images/StartsWith.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "结束于", "/Jib.WPF.Controls;component/Images/EndsWith.png")); CalcControlVisibility(ColumnType.String); } if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyConvertType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png")); CalcControlVisibility(ColumnType.Num); } if (TypeHelper.IsBoolType(FilterColumnInfo.PropertyConvertType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png")); CalcControlVisibility(ColumnType.Bool); } if (TypeHelper.IsDateTimeType(FilterColumnInfo.PropertyConvertType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png")); CalcControlVisibility(ColumnType.Date); } } else { if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "等于", "/Jib.WPF.Controls;component/Images/Equal.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "包含", "/Jib.WPF.Controls;component/Images/Contains.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "开始于", "/Jib.WPF.Controls;component/Images/StartsWith.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "结束于", "/Jib.WPF.Controls;component/Images/EndsWith.png")); CalcControlVisibility(ColumnType.String); } if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png")); CalcControlVisibility(ColumnType.Num); } if (TypeHelper.IsBoolType(FilterColumnInfo.PropertyType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png")); CalcControlVisibility(ColumnType.Bool); } if (TypeHelper.IsDateTimeType(FilterColumnInfo.PropertyType)) { FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "=", "/Jib.WPF.Controls;component/Images/Equal.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, ">", "/Jib.WPF.Controls;component/Images/GreaterThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, ">=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "<", "/Jib.WPF.Controls;component/Images/LessThan.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "<=", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png")); FilterSelectedItem.FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "!=", "/Jib.WPF.Controls;component/Images/NotEqual.png")); CalcControlVisibility(ColumnType.Date); } } } if (FilterColumnInfo != null && FilterColumnInfo.IsValid) { FilterSelectedItem.BoolPropertyValues.Clear(); _boundColumnPropertyAccessor = null; if (!string.IsNullOrWhiteSpace(FilterColumnInfo.PropertyPath)) { if (FilterColumnInfo.PropertyPath.Contains('.')) { throw new ArgumentException(string.Format("This version of the grid does not support a nested property path such as '{0}'. Please make a first-level property for filtering and bind to that.", FilterColumnInfo.PropertyPath)); } ParameterExpression arg = System.Linq.Expressions.Expression.Parameter(typeof(object), "x"); Type type = FilterSelectedItem.Grid.FilterType; System.Linq.Expressions.Expression expr = System.Linq.Expressions.Expression.Convert(arg, type); expr = System.Linq.Expressions.Expression.Property(expr, type, FilterColumnInfo.PropertyPath); if (!string.IsNullOrWhiteSpace(FilterColumnInfo.StringPath)) { System.Reflection.PropertyInfo propInfo2 = FilterSelectedItem.Grid.FilterType.GetProperty(FilterColumnInfo.PropertyPath); expr = System.Linq.Expressions.Expression.Property(expr, propInfo2.PropertyType, FilterColumnInfo.StringPath); } System.Linq.Expressions.Expression conversion = System.Linq.Expressions.Expression.Convert(expr, typeof(object)); _boundColumnPropertyAccessor = System.Linq.Expressions.Expression.Lambda <Func <object, object> >(conversion, arg).Compile(); if (_boundColumnPropertyAccessor != null) { List <object> result = new List <object>(); foreach (var i in FilterSelectedItem.Grid.ItemsSource) { AllSelectedPropertyChanged selectedModel = i as AllSelectedPropertyChanged; object value = _boundColumnPropertyAccessor(selectedModel); if (value != null) { if (result.Where(o => o.ToString() == value.ToString()).Count() == 0) { result.Add(value); } } else if (FilterColumnInfo.PropertyType == typeof(bool?) && FilterColumnInfo.IsSpecialState) { if (result.Where(o => o == value).Count() == 0) { result.Add(value); } } } try { result.Sort(); } catch { if (System.Diagnostics.Debugger.IsLogging()) { System.Diagnostics.Debugger.Log(0, "Warning", "There is no default compare set for the object type"); } } //foreach (var item in result) //{ // FilterSelectedItem.ColumnValue = item.ToString() + ","; //} //if (!string.IsNullOrWhiteSpace(FilterSelectedItem.ColumnValue)) //{ // FilterSelectedItem.ColumnValue = FilterSelectedItem.ColumnValue.Remove(FilterSelectedItem.ColumnValue.Length - 1); //} } } } }
void filter_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "FilterChanged") { ColumnFilterControl cf = sender as ColumnFilterControl; Predicate <object> predicate = null; if (!IsFilterWindow) { if (window != null) { predicate = FilterDataViewModel.Instance.FilterPredicate; window.Close(); } } else { foreach (var filter in Filters) { if (filter.HasPredicate) { if (predicate == null) { predicate = filter.GeneratePredicate(); } else { predicate = predicate.And(filter.GeneratePredicate()); } } if (cf.FilterText == null) { if (predicate == null) { predicate = filter.GeneratePredicate(); } else { predicate = predicate.And(filter.GeneratePredicate()); } } } } bool canContinue = true; var args = new CancelableFilterChangedEventArgs(predicate); if (BeforeFilterChanged != null && !IsResetting) { BeforeFilterChanged(this, args); canContinue = !args.Cancel; } if (canContinue) { ListCollectionView view = CollectionViewSource.GetDefaultView(this.ItemsSource) as ListCollectionView; if (view != null && view.IsEditingItem) { view.CommitEdit(); } if (view != null && view.IsAddingNew) { view.CommitNew(); } if (CollectionView != null) { try { CollectionView.Filter = predicate; } catch { } int count = 1; ObservableCollection <AllSelectedPropertyChanged> list = new ObservableCollection <AllSelectedPropertyChanged>(); foreach (var item in CollectionView) { AllSelectedPropertyChanged selectedModel = item as AllSelectedPropertyChanged; //selectedModel.Num= count++; list.Add(selectedModel); } foreach (var item in list) { if (item == null) { continue; } item.Num = count++; } //if(cf.FilterText!=null&& cf.FilterText.Trim() != "") //{ if (list != null && list.Count > 0) { FilterFinshItemsSource = list; if (AfterFilterChanged != null) { AfterFilterChanged(this, new FilterChangedEventArgs(predicate)); } } //} } } else { IsResetting = true; var ctrl = sender as ColumnFilterControl; ctrl.ResetControl(); IsResetting = false; } } }
private void SelectedModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "IsSelected") { return; } if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) { return; } AllSelectedPropertyChanged selectedModel = sender as AllSelectedPropertyChanged; if (selectedModel.IsSelected == "1") { AllChecked = true; if (!IsDefaultSelectAll) { foreach (var item in FilteredItemsSource) { AllSelectedPropertyChanged model = item as AllSelectedPropertyChanged; if (model == null) { continue; } if (model.IsSelected == "0" || model.IsSelected == null || model.IsSelected == "") { AllChecked = false; break; } } if (CheckedSelectedChanged != null) { if (this.SelectedItem != null) { CheckedSelectedChanged(this.SelectedItem, new CheckSelectedEventArgs(IsDefaultSelectAll)); } else { CheckedSelectedChanged(sender, new CheckSelectedEventArgs(IsDefaultSelectAll)); } } } } else { AllChecked = false; if (!IsDefaultSelectAll) { if (CheckedSelectedChanged != null) { if (this.SelectedItem != null) { CheckedSelectedChanged(this.SelectedItem, new CheckSelectedEventArgs(IsDefaultSelectAll)); } else { CheckedSelectedChanged(sender, new CheckSelectedEventArgs(IsDefaultSelectAll)); } } } } //if (this.Filters != null) // foreach (var filter in this.Filters) // filter.ResetControl(); }
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue) { base.OnItemsSourceChanged(oldValue, newValue); if (this.Columns.Count > 0) { CheckBox cbAllCheck = null; if (this.Columns[0].Header is CheckBox) { cbAllCheck = this.Columns[0].Header as CheckBox; } else if (this.Columns[1].Header is CheckBox) { cbAllCheck = this.Columns[1].Header as CheckBox; } if (cbAllCheck != null) { BindingOperations.SetBinding(cbAllCheck, CheckBox.IsCheckedProperty, new Binding() { Path = new PropertyPath("AllChecked"), Source = this, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); cbAllCheck.Click -= CbAllCheck_Click; cbAllCheck.Click += CbAllCheck_Click; int count = 0; foreach (var item in FilteredItemsSource) { count++; } if (count > 0) { AllChecked = true; foreach (var item in FilteredItemsSource) { AllSelectedPropertyChanged selectedModel = item as AllSelectedPropertyChanged; if (selectedModel == null) { return; } selectedModel.PropertyChanged -= SelectedModel_PropertyChanged; selectedModel.PropertyChanged += SelectedModel_PropertyChanged; if ((selectedModel.IsSelected != "1") && AllChecked) { AllChecked = false; } } } else { AllChecked = false; } } if (FilterFinshItemsSource != null && FilterFinshItemsSource.Count > 0) { FilterFinshItemsSource.Clear(); } if (btnFilter != null) { btnFilter.Content = "M9.4229997,18.347 C14.338999,18.347 18.345999,14.339 18.345999,9.4229999 18.345999,4.508 14.338999,0.5 9.4229997,0.5 4.5079998,0.5 0.5,4.508 0.5,9.4229999 0.5,14.339 4.5079998,18.347 9.4229997,18.347 z M15.733999,15.734 L17.732999,17.733 M16.972,16.972 L18.5,18.5"; } } }