Exemple #1
0
        private IDictionary <string, object> CreateDictionary(object source, string newValue, string oldValue)
        {
            IDictionary <string, object> valueDictionary = new Dictionary <string, object>();
            var dataSourcePath = ControlExt.GetDataSourcePath(this);

            if (!string.IsNullOrEmpty(DataSourcePath))
            {
                dataSourcePath = DataSourcePath;
            }
            valueDictionary["Field"]         = dataSourcePath;
            valueDictionary["DataObject"]    = source;
            valueDictionary["ChangedValue"]  = newValue;
            valueDictionary["PreviousValue"] = oldValue;
            return(valueDictionary);
        }
Exemple #2
0
        private static void CheckBox_DataUnChecked(object sender, RoutedEventArgs e)
        {
            DataFieldCheckBox dataFieldCheckBox = sender as DataFieldCheckBox;
            var path = ControlExt.GetDataSourcePath(dataFieldCheckBox);

            if (path != null)
            {
                var tmp = ControlExt.GetDataSource(dataFieldCheckBox);
                if (tmp is bool)
                {
                    ControlExt.SetDataSource(dataFieldCheckBox, false);
                    EnforceDoChange(dataFieldCheckBox, path, 0);
                }
            }
        }
Exemple #3
0
        private static void CheckBox_DataChecked(object sender, RoutedEventArgs e)
        {
            var dataFieldCheckBox = sender as DataFieldCheckBox;
            var path = ControlExt.GetDataSourcePath(dataFieldCheckBox);

            if (!string.IsNullOrEmpty(path))
            {
                var tmp = ControlExt.GetDataSource(dataFieldCheckBox);
                if (tmp == null)
                {
                    return;
                }
                var propValue = ComponentUtils.GetPropValue(tmp, path);
                if (dataFieldCheckBox != null)
                {
                    dataFieldCheckBox.IsChecked = true;
                    ControlExt.SetDataSource(dataFieldCheckBox, true);
                    EnforceDoChange(dataFieldCheckBox, path, 1);
                }
            }
        }
Exemple #4
0
        private static void SelectedDate_Changed(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            DatePicker picker = sender as DatePicker;

            if (picker != null)
            {
                ICommand changedCommand = picker.GetValue(ItemChangedCommandProperty) as ICommand;
                if (changedCommand != null)
                {
                    if (picker.SelectedDate != null)
                    {
                        IDictionary <string, object> valueDictionary = new Dictionary <string, object>
                        {
                            ["Field"]        = ControlExt.GetDataSourcePath(picker),
                            ["DataObject"]   = ControlExt.GetDataSource(picker),
                            ["ChangedValue"] = (DateTime)picker.SelectedDate,
                        };
                        changedCommand.Execute(valueDictionary);
                    }
                }
            }
        }
Exemple #5
0
        private void SendEventOnChanged()
        {
            // ok we can raise the event.
            var path       = ControlExt.GetDataSourcePath(this);
            var dataObject = DataObject;

            if (dataObject == null)
            {
                dataObject = ControlExt.GetDataSource(this);
            }
            var current = (IsChecked == true) ? 1 : 0;
            IDictionary <string, object> values = new Dictionary <string, object>();

            values.Add("DataObject", dataObject);
            values.Add("ChangedValue", current);
            values.Add("PreviousValue", _previous);
            values.Add("Field", path);
            if (!string.IsNullOrEmpty(path))
            {
                try
                {
                } catch (Exception ex)
                {
                }
            }
            if (Command != null)
            {
                Command.Execute(values);
            }
            else
            {
                DataFieldCheckBoxEventArgs args = new DataFieldCheckBoxEventArgs(DataFieldCheckBoxChangedEvent);
                args.ChangedValuesObjects = values;
                RaiseEvent(args);
            }
        }
Exemple #6
0
        private void EditorTextOnLostFocus(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(_previousDataArea) && (string.IsNullOrEmpty(this._currentDataArea)))
            {
                return;
            }
            if (_editorText == null)
            {
                _editorText = GetTemplateChild("PART_EditorText") as MultiLineTextEditor;
            }
            if (_editorText == null)
            {
                return;
            }

            // ok
            _dataAreaChanged = _previousDataArea != _editorText.Text;

            if (_dataAreaChanged)
            {
                _previousDataArea = _currentDataArea;
                _currentDataArea  = _editorText.Text;
                if (_editorText.Text != null)
                {
                    DataAreaFieldEventsArgs ev = new DataAreaFieldEventsArgs(DataAreaChangedEvent);
                    ev.FieldData = _editorText.Text;
                    ComponentFiller filler = new ComponentFiller();

                    var dataObject = ControlExt.GetDataSource(this);
                    if (dataObject == null)
                    {
                        dataObject = DataSource;
                    }

                    if (!string.IsNullOrEmpty(DataSourcePath))
                    {
                        var path = DataSourcePath;
                        if (string.IsNullOrEmpty(DataSourcePath))
                        {
                            path = ControlExt.GetDataSourcePath(this);
                        }
                        filler.FillDataObject(_editorText.Text, path, ref dataObject);
                        DataSource = dataObject;

                        IDictionary <string, object> valueDictionary = CreateDictionary(dataObject, _editorText.Text, _previousDataArea);

                        ev.ChangedValuesObjects = valueDictionary;

                        if (ItemChangedCommand != null)
                        {
                            ICommand ex = ItemChangedCommand;
                            if (ex.CanExecute(valueDictionary))
                            {
                                ex.Execute(valueDictionary);
                            }
                        }
                        RaiseEvent(ev);
                        _dataAreaChanged = false;
                    }
                    else
                    {
                        IDictionary <string, object> valueDictionary = CreateDictionary(dataObject, _editorText.Text, _previousDataArea);
                        if (ItemChangedCommand != null)
                        {
                            ICommand ex = ItemChangedCommand;
                            if (ex.CanExecute(valueDictionary))
                            {
                                ex.Execute(valueDictionary);
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        ///  This is a property changed util.
        /// </summary>
        /// <param name="dependencyObject"></param>
        /// <param name="eventArgs"></param>
        public static void PropertyChangedCb(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            // dry : the change is handled by the PasswordBox properties as well.
            if (dependencyObject is PasswordBox)
            {
                return;
            }
            if (dependencyObject is PercentTextBox)
            {
                PercentTextBox box = dependencyObject as PercentTextBox;
                box.LostFocus += Box_LostFocus1;
                return;
            }
            if (dependencyObject is SfDataGrid currentDataGrid)
            {
                //  currentDataGrid.CurrentCellEndEdit += CurrentDataGrid_CurrentCellEndEdit;
                currentDataGrid.RecordDeleted       += CurrentDataGrid_RecordDeleted;
                currentDataGrid.AddNewRowInitiating += CurrentDataGrid_AddNewRowInitiating;

                currentDataGrid.RowValidated   += CurrentDataGrid_RowValidated;
                currentDataGrid.PreviewKeyDown += CurrentDataGrid_PreviewKeyDown;
            }
            if (dependencyObject is DataArea)
            {
                var dataArea = dependencyObject as DataArea;
                dataArea.ItemChangedCommand = GetItemChangedCommand(dataArea);
                dataArea.DataSource         = GetDataSource(dataArea);
                dataArea.DataSourcePath     = GetDataSourcePath(dataArea);
                return;
            }
            if (dependencyObject is SfTimePicker)
            {
                SfTimePicker picker = dependencyObject as SfTimePicker;
                picker.ValueChanged += Picker_ValueChanged;
            }
            if (dependencyObject is DatePicker datePicker)
            {
                datePicker.SelectedDateChanged += SelectedDate_Changed;
            }
            if (dependencyObject is DataDatePicker)
            {
                DataDatePicker dataDatePicker = dependencyObject as DataDatePicker;
                dataDatePicker.DataDatePickerChanged += DataDatePicker_DataDatePickerChanged;
                return;
            }

            if (dependencyObject is TextBox)
            {
                TextBox box = dependencyObject as TextBox;
                box.TextChanged += TextBox_ChangedBehaviour;
                box.LostFocus   += Box_LostFocus;
                return;
            }
            if (dependencyObject is DataFieldCheckBox)
            {
                DataFieldCheckBox checkBox = dependencyObject as DataFieldCheckBox;
                var path = ControlExt.GetDataSourcePath(checkBox);
                if (!string.IsNullOrEmpty(path))
                {
                    var tmp = ControlExt.GetDataSource(checkBox);
                    if (tmp != null)
                    {
                        var propValue = ComponentUtils.GetPropValue(tmp, path);
                        if (propValue is string)
                        {
                            byte value = Convert.ToByte(propValue);
                            if (value > 0)
                            {
                                checkBox.IsChecked = true;
                            }
                        }
                        else
                        {
                            checkBox.IsChecked = Convert.ToBoolean(propValue);
                        }
                    }
                }
                //checkBox.Checked += CheckBox_DataChecked;
                // checkBox.Unchecked += CheckBox_DataUnChecked;
                checkBox.DataFieldCheckBoxChanged += CheckBox_DataFieldCheckBoxChanged;
                return;
            }
            if (dependencyObject is CheckBox checkBox1)
            {
                checkBox1.Checked   += CheckBox_Checked;
                checkBox1.Unchecked += CheckBox_Unchecked;
                checkBox1.Click     += checkBox_Clicked;
                return;
            }
            if (dependencyObject is ComboBox comboBox)
            {
                // here we do the combox box.
                comboBox.SelectionChanged += ComboBox_SelectionChanged;
            }
        }