Пример #1
0
        private static void OnValidatesOnDataErrorsChanged(BindableObject view, object oldvalue, object newvalue)
        {
            if (!Convert.ToBoolean(newvalue) || !(view is IXfxValidatableElement))
            {
                return;
            }

            var binding           = view.GetBinding(Entry.TextProperty);
            var boundPropertyName = binding.Path;

            ((VisualElement)view).Behaviors.Add(new ValidatesOnNotifyDataErrors {
                PropertyName = boundPropertyName
            });
        }
    public static void SetCurrentValue(this BindableObject self, BindableProperty property, object value)
    {
        if (self == null)
        {
            throw new ArgumentNullException(nameof(self));
        }
        if (property == null)
        {
            throw new ArgumentNullException(nameof(property));
        }
        var backupBinding   = self.GetBinding(property); //backup binding
        var backupConverter = backupBinding.Converter;   //backup orig. converter

        self.SetValue(property, value);                  //removes the binding.
        backupBinding.Converter = new DefaultValueConverter {
            DefaultValue = value
        };                                               //change the converter
        self.SetBinding(property, backupBinding);        //target should be updated to the default value
        var converterField = backupBinding.GetType().GetTypeInfo().GetDeclaredField("_converter");

        converterField.SetValue(backupBinding, backupConverter);        //restore the converter
    }