void ColumnOptionControl_Loaded(object sender, RoutedEventArgs e)
        {
            //Check the Grid for Building commmands and Visibility
            DataGridColumn       column    = null;
            DataGridColumnHeader colHeader = null;

            UIElement parent = (UIElement)VisualTreeHelper.GetParent(this);

            while (parent != null)
            {
                parent = (UIElement)VisualTreeHelper.GetParent(parent);
                if (colHeader == null)
                {
                    colHeader = parent as DataGridColumnHeader;
                }

                if (Grid == null)
                {
                    Grid = parent as JibGrid;
                }
            }

            if (colHeader != null)
            {
                column = colHeader.Column;
            }

            FilterColumnInfo = new OptionColumnInfo(column, Grid.FilterType);

            CanUserFreeze = Grid.CanUserFreeze;
            CanUserGroup  = Grid.CanUserGroup;
            if (column != null)
            {
                object oCanUserFreeze = column.GetValue(ColumnConfiguration.CanUserFreezeProperty);
                if (oCanUserFreeze != null && (bool)oCanUserFreeze)
                {
                    CanUserFreeze = (bool)oCanUserFreeze;
                }

                object oCanUserGroup = column.GetValue(ColumnConfiguration.CanUserGroupProperty);
                if (oCanUserGroup != null && (bool)oCanUserGroup)
                {
                    CanUserGroup = (bool)oCanUserGroup;
                }
            }

            Grid.RegisterColumnOptionControl(this);
            ResetVisibility();
        }
Ejemplo n.º 2
0
        void ColumnFilterControl_Loaded(object sender, RoutedEventArgs e)
        {
            DataGridColumn       column    = null;
            DataGridColumnHeader colHeader = null;

            UIElement parent = (UIElement)VisualTreeHelper.GetParent(this);

            while (parent != null)
            {
                parent = (UIElement)VisualTreeHelper.GetParent(parent);
                if (colHeader == null)
                {
                    colHeader = parent as DataGridColumnHeader;
                }

                if (Grid == null)
                {
                    Grid = parent as JibGrid;
                }
            }

            if (colHeader != null)
            {
                column = colHeader.Column;
            }

            CanUserFilter         = Grid.CanUserFilter;
            CanUserFreeze         = Grid.CanUserFreeze;
            CanUserGroup          = Grid.CanUserGroup;
            CanUserSelectDistinct = Grid.CanUserSelectDistinct;


            if (column != null)
            {
                object oCanUserFilter = column.GetValue(ColumnConfiguration.CanUserFilterProperty);
                if (oCanUserFilter != null)
                {
                    CanUserFilter = (bool)oCanUserFilter;
                }

                object oCanUserFreeze = column.GetValue(ColumnConfiguration.CanUserFreezeProperty);
                if (oCanUserFreeze != null)
                {
                    CanUserFreeze = (bool)oCanUserFreeze;
                }

                object oCanUserGroup = column.GetValue(ColumnConfiguration.CanUserGroupProperty);
                if (oCanUserGroup != null)
                {
                    CanUserGroup = (bool)oCanUserGroup;
                }

                object oCanUserSelectDistinct = column.GetValue(ColumnConfiguration.CanUserSelectDistinctProperty);
                if (oCanUserSelectDistinct != null)
                {
                    CanUserSelectDistinct = (bool)oCanUserSelectDistinct;
                }
            }


            if (Grid.FilterType == null)
            {
                return;
            }

            FilterColumnInfo = new OptionColumnInfo(column, Grid.FilterType);

            Grid.RegisterOptionControl(this);

            FilterOperations.Clear();
            if (FilterColumnInfo.PropertyType != null)
            {
                if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "Contains", "/Jib.WPF.Controls;component/Images/Contains.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "Starts With", "/Jib.WPF.Controls;component/Images/StartsWith.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "Ends With", "/Jib.WPF.Controls;component/Images/EndsWith.png"));
                }
                FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "Equals", "/Jib.WPF.Controls;component/Images/Equal.png"));
                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, "Greater Than", "/Jib.WPF.Controls;component/Images/GreaterThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, "Greater Than or Equal", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "Less Than", "/Jib.WPF.Controls;component/Images/LessThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "Greater Than or Equal", "/Jib.WPF.Controls;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "Not Equal", "/Jib.WPF.Controls;component/Images/NotEqual.png"));
                }
                SelectedFilterOperation = FilterOperations[0];
            }

            if (FilterColumnInfo != null && FilterColumnInfo.IsValid)
            {
                foreach (var i in DistinctPropertyValues.Where(i => i.IsChecked))
                {
                    i.IsChecked = false;
                }
                DistinctPropertyValues.Clear();
                FilterText = string.Empty;
                _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));
                    }

                    this.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);
                    expr = System.Linq.Expressions.Expression.Property(expr, Grid.FilterType, FilterColumnInfo.PropertyPath);
                    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
                {
                    this.Visibility = System.Windows.Visibility.Collapsed;
                }
                object oDefaultFilter = column.GetValue(ColumnConfiguration.DefaultFilterProperty);
                if (oDefaultFilter != null)
                {
                    FilterText = (string)oDefaultFilter;
                }
            }

            CalcControlVisibility();
        }