Beispiel #1
0
        private void InitEditing(FrameworkElement gridViewCell)
        {
            DependencyProperty _viewProperty  = null;
            DependencyProperty _viewProperty2 = null;

            switch (this.Column.ViewType)
            {
            case EViewType.Text:
            case EViewType.Integer:
            case EViewType.Decimal:
            case EViewType.Currency:
            case EViewType.Date:
                _viewProperty = DsxRowCell <TextBlock> .TextProperty;
                break;


            case EViewType.Boolean:
            case EViewType.CheckBox:
                _viewProperty = DsxRowCell <BulletChrome> .IsCheckedProperty;
                break;

            case EViewType.Image:
                _viewProperty = DsxRowCell <Image> .ImgSourceProperty;
                break;

            case EViewType.Progress:
                _viewProperty  = DsxRowCell <DsxCellProgressBar> .ValueProperty;
                _viewProperty2 = DsxRowCell <DsxCellProgressBar> .TextProperty;
                break;
            }

            //  hosting panel
            this.EditPanel                     = new Grid();
            this.EditPanel.Focusable           = false;
            this.EditPanel.Margin              = new Thickness(3);
            this.EditPanel.Background          = (Brush)Application.Current.Resources["NormalBrush"];
            this.EditPanel.HorizontalAlignment = HorizontalAlignment.Stretch;
            this.EditPanel.VerticalAlignment   = this.IsFilter ? VerticalAlignment.Center : VerticalAlignment.Top;

            EEditType _editType = this.IsFilter ? this.Column.FilterType : this.Column.EditType;

            switch (_editType)
            {
            case EEditType.TextBox:
                this.EditProperty = TextBox.TextProperty;

                TextBox _textBox = new TextBox();
                _textBox.FocusVisualStyle = null;
                _textBox.Margin           = new Thickness(0, 1, 0, 1);
                _textBox.Padding          = new Thickness(1, -1, 1, -1);
                _textBox.TextWrapping     = this.Column.DataGrid.ItemFixHeight != 0.0 ? TextWrapping.NoWrap : TextWrapping.Wrap;

                switch (this.Column.CellHAlign)
                {
                case HorizontalAlignment.Left:      _textBox.TextAlignment = TextAlignment.Left;    break;

                case HorizontalAlignment.Right:     _textBox.TextAlignment = TextAlignment.Right;   break;

                case HorizontalAlignment.Center:    _textBox.TextAlignment = TextAlignment.Center;  break;
                }

                this.EditCtrl = _textBox;
                break;

            case EEditType.CheckBox:

                this.EditProperty = CheckBox.IsCheckedProperty;

                CheckBox _checkBox = new CheckBox();
                _checkBox.IsThreeState     = this.IsFilter;
                _checkBox.FocusVisualStyle = null;
                _checkBox.KeyDown         += delegate { _checkBox.IsChecked = !_checkBox.IsChecked; };

                if (this.IsFilter)
                {
                    _checkBox.IsChecked        = null;
                    this.Column.FilterCriteria = EFilterCriteria.Equals;
                }

                this.EditCtrl = _checkBox;

                this.EditPanel.HorizontalAlignment = (HorizontalAlignment)this.Column.CellHAlign;

                break;

            case EEditType.DatePicker:

                this.EditProperty = DsxCellDatePicker.SelectedDateProperty;


                DsxCellDatePicker _datePicker = new DsxCellDatePicker();
                _datePicker.CalendarStyle    = (Style)Application.Current.Resources[typeof(Calendar)];
                _datePicker.FocusVisualStyle = null;
                _datePicker.Margin           = new Thickness(0);
                _datePicker.Padding          = new Thickness(0);
                _datePicker.Background       = (Brush)Application.Current.Resources["NormalBrush"];

                this.EditCtrl = _datePicker;

                if (!this.IsFilter)
                {
                    this.EditPanel.HorizontalAlignment = (HorizontalAlignment)this.Column.CellHAlign;
                }

                break;

            case EEditType.ComboBox:

                this.EditProperty = DsxCellComboBox.SelectedValueProperty;

                DsxCellComboBox _comboBox = new DsxCellComboBox();
                _comboBox.FocusVisualStyle = null;
                _comboBox.Margin           = new Thickness(0);
                _comboBox.Padding          = new Thickness(0);
                _comboBox.Background       = (Brush)Application.Current.Resources["NormalBrush"];
                _comboBox.BorderThickness  = new Thickness(0);

                _comboBox.IsTextSearchEnabled = true;
                _comboBox.IsEditable          = false;

                _comboBox.SelectedValuePath = this.Column.CellContentSelectedValuePath;
                _comboBox.DisplayMemberPath = this.Column.CellContentDisplayMemberPath;
                _comboBox.ItemsSource       = this.Column.CellContentItemsSource;

                this.EditCtrl = _comboBox;

                break;

            case EEditType.Slider:

                this.EditProperty  = DsxCellSlider.ValueProperty;
                this.EditProperty2 = DsxCellSlider.TextProperty;

                DsxCellSlider _sliderCtrl = new DsxCellSlider();
                _sliderCtrl.FocusVisualStyle  = null;
                _sliderCtrl.Margin            = new Thickness(2, 2, 8, 0);
                _sliderCtrl.Padding           = new Thickness(0);
                _sliderCtrl.Foreground        = this.Column.CellForeground;
                _sliderCtrl.Background        = (Brush)Application.Current.Resources["NormalBrush"];
                _sliderCtrl.ContentBackground = this.Column.CellContentBackground;
                _sliderCtrl.TextAlignment     = TextAlignment.Right;
                _sliderCtrl.BorderThickness   = new Thickness(0);

                this.EditCtrl = _sliderCtrl;

                break;
            }

            this.EditCtrl.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            this.EditCtrl.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
            this.EditCtrl.Margin          = new Thickness(0);
            this.EditCtrl.BorderThickness = new Thickness(0);

            this.EditCtrl.DataContext = this.IsFilter ? this.Column : gridViewCell.DataContext;
            this.EditCtrl.IsTabStop   = !this.IsFilter;

            // bindings
            BindingExpression _bindingExpr  = null;
            Binding           _binding      = null;
            BindingExpression _bindingExpr2 = null;
            Binding           _binding2     = null;

            if (_viewProperty != null)
            {
                if (this.IsFilter)
                {
                    _binding = new Binding(DsxColumn.FilterTextValueProperty.Name);

                    if (_editType == EEditType.CheckBox)
                    {
                        _binding.FallbackValue = null;
                    }
                    if (_editType == EEditType.DatePicker)
                    {
                        _binding.Converter = new DsxCellDateConverter();
                    }
                }
                else
                {
                    _bindingExpr = gridViewCell.GetBindingExpression(_viewProperty);
                    _binding     = new Binding(_bindingExpr.ParentBinding.Path.Path);
                }
                _binding.Mode = BindingMode.TwoWay;
                _binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                this.EditBinding = this.EditCtrl.SetBinding(this.EditProperty, _binding);
            }

            if (_viewProperty2 != null && !this.IsFilter)
            {
                _bindingExpr2                 = gridViewCell.GetBindingExpression(_viewProperty2);
                _binding2                     = new Binding(_bindingExpr2.ParentBinding.Path.Path);
                _binding2.Mode                = BindingMode.TwoWay;
                _binding2.StringFormat        = this.Column.StringFormat;
                _binding2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                this.EditBinding2 = this.EditCtrl.SetBinding(this.EditProperty2, _binding2);
            }

            this.EditOrgValue = this.EditCtrl.GetValue(this.EditProperty);

            //  filter button
            if (this.IsFilter && _editType != EEditType.CheckBox)
            {
                Binding _clearBinding = new Binding("ComputedFilterClearVisibility");
                _clearBinding.Mode = BindingMode.OneWay;
                _clearBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                DsxFilterPopup _criteria = new DsxFilterPopup(this.Column);
                _criteria.Focusable           = false;
                _criteria.HorizontalAlignment = HorizontalAlignment.Left;
                _criteria.SetValue(DockPanel.DockProperty, Dock.Left);

                DsxFilterClear _clearBtn = new DsxFilterClear();
                _clearBtn.DataContext = this.EditCtrl.DataContext;

                _clearBtn.SetBinding(FrameworkElement.VisibilityProperty, _clearBinding);
                _clearBtn.SetValue(DockPanel.DockProperty, Dock.Right);
                _clearBtn.Click += delegate { this.Column.FilterTextValue = String.Empty; };

                DockPanel _dockPanel = new DockPanel();

                _dockPanel.Children.Add(_criteria);
                _dockPanel.Children.Add(_clearBtn);
                _dockPanel.Children.Add(this.EditCtrl);

                this.EditPanel.Children.Add(_dockPanel);
            }
            else
            {
                this.EditPanel.Children.Add(this.EditCtrl);
            }
            this.VisualChildren.Add(this.EditPanel);

            switch (this.Column.EditType)
            {
            case EEditType.TextBox:
                (this.EditCtrl as TextBox).SelectAll();
                break;

            case EEditType.CheckBox:
                break;

            case EEditType.DatePicker:
                break;
            }

            this.EditCtrl.Dispatcher.BeginInvoke(new Action(delegate
            {
                this.EditCtrl.Focus();
            }),
                                                 DispatcherPriority.Input);
        }
Beispiel #2
0
 public ChangePropertiesAttribute(EChangeScope scope, EEditType editType)
 {
     this.scope             = scope;
     this.editType          = editType;
     MayRequireRevalidation = true;
 }