Exemplo n.º 1
0
        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 ExDataGrid;
                }
            }

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

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

            // Right adjust numeric column
            if (column is DataGridBoundColumn boundColumn)
            {
                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    boundColumn.ElementStyle = _rightCellStyle;
                }
            }

            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();
        }
Exemplo 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 ExDataGrid;
                }
            }

            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)
            {
                FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Equals, "Equals", "/Capnode.Wpf;component/Images/Equal.png"));
                if (TypeHelper.IsStringType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.Contains, "Contains", "/Capnode.Wpf;component/Images/Contains.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.StartsWith, "Starts With", "/Capnode.Wpf;component/Images/StartsWith.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.EndsWith, "Ends With", "/Capnode.Wpf;component/Images/EndsWith.png"));
                }

                if (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.NotEquals, "Not Equal", "/Capnode.Wpf;component/Images/NotEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThan, "Greater Than", "/Capnode.Wpf;component/Images/GreaterThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.GreaterThanEqual, "Greater Than or Equal", "/Capnode.Wpf;component/Images/GreaterThanEqual.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThan, "Less Than", "/Capnode.Wpf;component/Images/LessThan.png"));
                    FilterOperations.Add(new FilterOperationItem(Enums.FilterOperation.LessThanEqual, "Less Than or Equal", "/Capnode.Wpf;component/Images/LessThanEqual.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 (TypeHelper.IsNumbericType(FilterColumnInfo.PropertyType))
                {
                    CanUserSelectDistinct = false;
                    Visibility            = Visibility.Visible;
                }
                else if (!string.IsNullOrWhiteSpace(FilterColumnInfo.PropertyPath))
                {
                    Visibility = Visibility.Visible;
                    ParameterExpression arg        = linq.Expression.Parameter(typeof(object), "x");
                    linq.Expression     expr       = PropertyExpression(Grid.FilterType, FilterColumnInfo.PropertyPath, arg);
                    linq.Expression     conversion = linq.Expression.Convert(expr, typeof(object));
                    _boundColumnPropertyAccessor = linq.Expression.Lambda <Func <object, object> >(conversion, arg).Compile();
                }
                else
                {
                    Visibility = Visibility.Collapsed;
                }

                object oDefaultFilter = column.GetValue(ColumnConfiguration.DefaultFilterProperty);
                if (oDefaultFilter != null)
                {
                    FilterText = (string)oDefaultFilter;
                }
            }

            CalcControlVisibility();
        }