/// <summary>
        /// Method will subscibe and unsubsribe Error changed event
        /// Get bindable property path of text property
        /// </summary>
        public void CheckValidation()
        {
            // Reset variables values
            ErrorMessage = "";
            HasError     = false;
            BindingPath  = "";

            if (_NotifyErrors != null)
            {
                // Unsubscribe event
                _NotifyErrors.ErrorsChanged += _NotifyErrors_ErrorsChanged;
                _NotifyErrors = null; // Set null value on binding context change
            }

            // Remove notify scroll to property
            if (_NotifyScroll != null)
            {
                _NotifyScroll.ScrollToProperty -= NotifyScroll_ScrollToProperty;
                _NotifyScroll = null;
            }

            // Do nothing if show error message property value is false
            if (!this.ShowErrorMessage || this.View is null)
            {
                return;
            }

            if (this.View.BindingContext != null && this.View.BindingContext is INotifyDataErrorInfo)
            {
                // Get
                _NotifyErrors = this.View.BindingContext as INotifyDataErrorInfo;

                if (_NotifyErrors == null)
                {
                    return;
                }

                // Subscribe event
                _NotifyErrors.ErrorsChanged += _NotifyErrors_ErrorsChanged;

                // Remove notify scroll to property
                if (this.View.BindingContext is INotifyScrollToProperty)
                {
                    _NotifyScroll = this.View.BindingContext as INotifyScrollToProperty;
                    _NotifyScroll.ScrollToProperty += NotifyScroll_ScrollToProperty;
                }

                this.BindingPath = this.View.GetBindingPath(BindableProperty);
                SetPlaceHolder();
            }
        }
        /// <summary>
        /// Method will subscibe and unsubsribe Error changed event
        /// Get bindable property path of text property
        /// </summary>
        public void CheckValidation()
        {
            // Reset variables values
            // Set 'HasError' = false
            // Set 'ErrorMessage' = "";
            InvokeSetPrivatePropertyAction(false, "");

            BindingPath = "";
            //this.Placeholder = "";

            if (_NotifyErrors != null)
            {
                // Unsubscribe event
                _NotifyErrors.ErrorsChanged += _NotifyErrors_ErrorsChanged;
                _NotifyErrors = null; // Set null value on binding context change
            }

            // Remove notify scroll to property
            if (_NotifyScroll != null)
            {
                _NotifyScroll.ScrollToProperty -= NotifyScroll_ScrollToProperty;
                _NotifyScroll = null;
            }

            // Do nothing if show error message property value is false
            if (!this._control.ShowErrorMessage)
            {
                return;
            }

            if (this._control.BindingContext != null && this._control.BindingContext is INotifyDataErrorInfo)
            {
                // Get
                _NotifyErrors = this._control.BindingContext as INotifyDataErrorInfo;

                // Return do nothing for your object
                if (_NotifyErrors == null)
                {
                    return;
                }

                // Remove notify scroll to property
                if (_control.BindingContext is INotifyScrollToProperty)
                {
                    _NotifyScroll = _control.BindingContext as INotifyScrollToProperty;
                    _NotifyScroll.ScrollToProperty += NotifyScroll_ScrollToProperty;
                }

                // Subscribe event
                _NotifyErrors.ErrorsChanged += _NotifyErrors_ErrorsChanged;

                // get property name for windows and other operating system
                // for windows 10 property name will be : properties
                // And other operation system its value : _properties
                string condition = "properties";

                // Get bindable properties
                var _propertiesFieldInfo = typeof(BindableObject)
                                           .GetRuntimeFields()
                                           .Where(x => x.IsPrivate == true && x.Name.Contains(condition))
                                           .FirstOrDefault();

                // Get Control
                var bindable = (BindableObject)_control;

                // Get value
                var _properties = _propertiesFieldInfo
                                  .GetValue(bindable) as IList;

                if (_properties == null)
                {
                    return;
                }

                // Get first object
                var fields = _properties[0]
                             .GetType()
                             .GetRuntimeFields();

                // Get binding field info
                FieldInfo bindingFieldInfo = fields.FirstOrDefault(x => x.Name.Equals("Binding"));
                // Get property field info
                FieldInfo propertyFieldInfo = fields.FirstOrDefault(x => x.Name.Equals("Property"));


                foreach (var item in _properties)
                {
                    // Now get binding and property value
                    Binding          binding  = bindingFieldInfo.GetValue(item) as Binding;
                    BindableProperty property = propertyFieldInfo.GetValue(item) as BindableProperty;
                    if (binding != null && property != null && property.PropertyName.Equals(this._toValidatePropertyName))
                    {
                        // set binding path
                        BindingPath = binding.Path;
                        SetPlaceHolder();
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Method will subscibe and unsubsribe Error changed event
        /// Get bindable property path of text property
        /// </summary>
        public void CheckValidation()
        {
            // Reset variables values
            // Set 'HasError' = false
            // Set 'ErrorMessage' = "";
            SetPrivateFields(false, "");

            BindingPath = "";
            //this.Placeholder = "";

            if (_NotifyErrors != null)
            {
                // Unsubscribe event
                _NotifyErrors.ErrorsChanged += _NotifyErrors_ErrorsChanged;
                _NotifyErrors = null; // Set null value on binding context change
            }

            // Remove notify scroll to property
            if (_NotifyScroll != null)
            {
                _NotifyScroll.ScrollToProperty -= NotifyScroll_ScrollToProperty;
                _NotifyScroll = null;
            }

            if (string.IsNullOrEmpty(this.BindingProperty))
            {
                return;
            }

            // Set binding path
            BindingPath = this.BindingProperty;

            if (this.BindingContext != null && this.BindingContext is INotifyDataErrorInfo)
            {
                // Get
                _NotifyErrors = this.BindingContext as INotifyDataErrorInfo;

                // Return do nothing for your object
                if (_NotifyErrors == null)
                {
                    return;
                }

                // Remove notify scroll to property
                if (this.BindingContext is INotifyScrollToProperty)
                {
                    _NotifyScroll = this.BindingContext as INotifyScrollToProperty;
                    _NotifyScroll.ScrollToProperty += NotifyScroll_ScrollToProperty;
                }

                // Subscribe event
                _NotifyErrors.ErrorsChanged += _NotifyErrors_ErrorsChanged;

                // get property name for windows and other operating system
                // for windows 10 property name will be : properties
                // And other operation system its value : _properties
                string condition = "properties";

                // Get bindable properties
                var _propertiesFieldInfo = typeof(BindableObject)
                                           .GetRuntimeFields()
                                           .Where(x => x.IsPrivate == true && x.Name.Contains(condition))
                                           .FirstOrDefault();
            }
        }