Exemplo n.º 1
0
        //Simple helper method which creates the FilterColumnInfo object for a column.  If a binding
        //is defined for the column we use that.  If that fails we fallback to using the SortMemberPath
        private FilterColumnInfo CreateFilterColumnInfo(DataGridColumn column)
        {
            var col         = new FilterColumnInfo();
            var boundColumn = column as DataGridBoundColumn;

            if (column != null)
            {
                if (boundColumn != null && column.SortMemberPath == null)
                {
                    col.PropertyPath = boundColumn.Binding.Path.Path;

                    try
                    {
                        var propertyType = col.PropertyType = FilterType.GetProperty(boundColumn.Binding.Path.Path).PropertyType;

                        if (propertyType != null)
                        {
                            col.PropertyType = propertyType;
                        }
                    }
                    catch (Exception)
                    {
                        var t1 = typeof(String);
                        col.PropertyType = new TypeDelegator(t1);
                    }

                    col.Converter            = boundColumn.Binding.Converter;
                    col.ConverterCultureInfo = boundColumn.Binding.ConverterCulture;
                    col.ConverterParameter   = boundColumn.Binding.ConverterParameter;
                }
                else if (column.SortMemberPath.Length > 0)
                {
                    col.PropertyPath = column.SortMemberPath;
                    try
                    {
                        var propertyType = FilterType.GetProperty(column.SortMemberPath).PropertyType;
                        if (propertyType != null)
                        {
                            if (propertyType == typeof(DateTime?))
                            {
                                propertyType = typeof(DateTime);
                            }
                            col.PropertyType = propertyType;
                        }
                    }
                    catch (Exception)
                    {
                        var t1 = typeof(String);
                        col.PropertyType = new TypeDelegator(t1);
                    }
                }
            }
            return(col);
        }
Exemplo n.º 2
0
 /// <summary>
 /// If a filterColumnInfo is set, the control is visible.  As each ColumnOptionControl is loaded in the grid, the relating column
 /// is used to build FilterColumnInfo for the control.
 /// </summary>
 /// <param name="filterColumnInfo">Binding information about the column</param>
 internal void ResetOptionValues(FilterColumnInfo filterColumnInfo)
 {
     FilterColumnInfo = filterColumnInfo;
     if (!CanGroup && !CanPin)
     {
         Visibility = Visibility.Collapsed;
     }
     else
     {
         if (!string.IsNullOrWhiteSpace(filterColumnInfo.PropertyPath))
         {
             Visibility = Visibility.Visible;
         }
         else
         {
             Visibility = Visibility.Collapsed;
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// ResetFilterValues is called when the column is bound ColumnFilterHeader
        /// </summary>
        /// <param name="filterColumnInfo">Information about the column binding object</param>
        internal void ResetFilterValues(FilterColumnInfo filterColumnInfo)
        {
            Visibility = Visibility.Collapsed;
            if (Column != null)
            {
                //  foreach (var i in DistinctPropertyValues.Where(i => i.IsChecked))
                //        i.IsChecked = false;
                //      DistinctPropertyValues.Clear();
                FilterText = string.Empty;
                _boundColumnPropertyAccessor = null;
                FilterColumnInfo             = filterColumnInfo;

                if (FilterColumnInfo.PropertyPath.Length > 0)
                {
                    //           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));

                    Visibility = System.Windows.Visibility.Visible;
                    ParameterExpression arg = System.Linq.Expressions.Expression.Parameter(typeof(object), "x");
                    System.Linq.Expressions.Expression expr = System.Linq.Expressions.Expression.Convert(arg, Grid.FilterType);
                    try
                    {
                        expr = System.Linq.Expressions.Expression.Property(expr, Grid.FilterType, FilterColumnInfo.PropertyPath);
                    }
                    catch (Exception)
                    {
                    }

                    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();
                }
                else
                {
                    Visibility = Visibility.Collapsed;
                }
                ConfigureFilterOptions();
            }
        }