コード例 #1
0
        private static BindingMode SetBindingMode(GridColumnBase column, PropertyPath path)
        {
            var isModeSet   = false;
            var bindingMode = BindingMode.TwoWay;
            PropertyDescriptorCollection itemproperties = null;

            if (column.GridBase != null)
            {
                if (column.GridBase is SfTreeGrid)
                {
                    var SfTreeGrid = (column.GridBase as SfTreeGrid);
                    if (SfTreeGrid.View != null)
                    {
                        itemproperties = SfTreeGrid.View.GetItemProperties();
                    }
                }
                else
                {
                    var sfDataGrid = (column.GridBase as SfDataGrid);
                    if (sfDataGrid.View != null)
                    {
                        itemproperties = sfDataGrid.View.GetItemProperties();
                    }
                }
            }

            if (itemproperties != null)
            {
                var propDesc = itemproperties.GetPropertyDescriptor(column.MappingName);
                if (propDesc != null)
                {
#if WPF
                    bindingMode = propDesc.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
#else
                    bindingMode = (propDesc.SetMethod == null || !propDesc.SetMethod.IsPublic) ? BindingMode.OneWay : BindingMode.TwoWay;
#endif
                    isModeSet = true;
                }
            }

            //While implementing the IDataErroInfo, will generate Error read only property. Based on this property created a column when AutoGenerateColumn is True.
            //so that mode will be reset based on AllowEditing property of that Error column.

            if (!isModeSet)
            {
                if (column.AllowEditing && column.CanEditCell())
                {
                    bindingMode = BindingMode.TwoWay;
                }
                else
                {
                    bindingMode = BindingMode.OneWay;
                }
                isModeSet = true;
            }
            return(bindingMode);
        }
コード例 #2
0
        internal static Binding CreateEditableBinding(this string mappingName, GridColumnBase column, bool enableErrorNotification)
        {
            bool canBindTwoWay = column != null?column.CanEditCell() : true;

            var binding = new Binding
            {
                Path = new PropertyPath(mappingName),
                Mode = canBindTwoWay ? BindingMode.TwoWay : BindingMode.OneWay,
#if WPF
                NotifyOnValidationError = enableErrorNotification,
                ValidatesOnDataErrors   = enableErrorNotification,
#if !SyncfusionFramework4_0
                ValidatesOnNotifyDataErrors = enableErrorNotification
#endif
#endif
            };

            return(binding);
        }
コード例 #3
0
        private static Binding CreateEditBindingBase(this Binding source, bool enableErrorNotification, GridColumnBase column)
        {
            //WPF - 18160 - If AllowEditing of a column is True, mode can be determined by allowediting and
            //CanEditCell() which return true for all columns other than GridImageColumn and GridHyperLinkColumn
            bool canBindTwoWay = column.CanEditCell();
            UpdateSourceTrigger updateSourceTrigger = column.isvaluebindingcreated ? column.UpdateTrigger : source.UpdateSourceTrigger;
            var binding = new Binding
            {
                Converter          = (source.Converter is CultureFormatConverter || source.Converter is DisplayMemberConverter) ? null : source.Converter,
                ConverterParameter = (source.Converter is CultureFormatConverter || source.Converter is DisplayMemberConverter) ? null : source.ConverterParameter,
                Path = source.Path,
                UpdateSourceTrigger =
                    updateSourceTrigger == UpdateSourceTrigger.PropertyChanged
                        ? UpdateSourceTrigger.Explicit
                        : updateSourceTrigger,
#if WPF
                BindsDirectlyToSource   = source.BindsDirectlyToSource,
                ConverterCulture        = source.ConverterCulture,
                FallbackValue           = source.FallbackValue,
                NotifyOnValidationError = enableErrorNotification,
                StringFormat            = source.StringFormat,
                TargetNullValue         = source.TargetNullValue,
                ValidatesOnDataErrors   = enableErrorNotification,
                ValidatesOnExceptions   = source.ValidatesOnExceptions,
#if !SyncfusionFramework4_0
                ValidatesOnNotifyDataErrors = enableErrorNotification,
                Delay = source.Delay,
#endif
                AsyncState                  = source.AsyncState,
                BindingGroupName            = source.BindingGroupName,
                IsAsync                     = source.IsAsync,
                NotifyOnSourceUpdated       = source.NotifyOnSourceUpdated,
                NotifyOnTargetUpdated       = source.NotifyOnTargetUpdated,
                UpdateSourceExceptionFilter = source.UpdateSourceExceptionFilter,
                XPath = source.XPath
#endif
            };

            if (column.GridBase != null)
            {
                if (column.GridBase is SfDataGrid)
                {
                    binding.Mode = (column.GridBase as SfDataGrid).SelectionController.CurrentCellManager.IsAddNewRow ?
                                   CreateBindingForAddNewRow(column as GridColumn) :
                                   (!column.isvaluebindingcreated ? source.Mode :
                                    SetBindingMode(column, source.Path));
                }
                else
                {
                    binding.Mode = !column.isvaluebindingcreated ? source.Mode : SetBindingMode(column, source.Path);
                }
            }

            if (source.ElementName != null)
            {
                binding.ElementName = source.ElementName;
                return(binding);
            }
            if (source.RelativeSource != null)
            {
                binding.RelativeSource = source.RelativeSource;
                return(binding);
            }
            if (source.Source != null)
            {
                binding.Source = source.Source;
            }
#if WPF
            foreach (var validationRule in source.ValidationRules)
            {
                binding.ValidationRules.Add(validationRule);
            }
#endif
            return(binding);
        }