Beispiel #1
0
    public static bool TryParseSelectableValueFromString <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TValue>(
        this InputBase <TValue> input, string?value,
        [MaybeNullWhen(false)] out TValue result,
        [NotNullWhen(false)] out string?validationErrorMessage)
    {
        try
        {
            // We special-case bool values because BindConverter reserves bool conversion for conditional attributes.
            if (typeof(TValue) == typeof(bool))
            {
                if (TryConvertToBool(value, out result))
                {
                    validationErrorMessage = null;
                    return(true);
                }
            }
            else if (typeof(TValue) == typeof(bool?))
            {
                if (TryConvertToNullableBool(value, out result))
                {
                    validationErrorMessage = null;
                    return(true);
                }
            }
            else if (BindConverter.TryConvertTo <TValue>(value, CultureInfo.CurrentCulture, out var parsedValue))
            {
                result = parsedValue;
                validationErrorMessage = null;
                return(true);
            }

            result = default;
            validationErrorMessage = $"The {input.DisplayName ?? input.FieldIdentifier.FieldName} field is not valid.";
            return(false);
        }
        catch (InvalidOperationException ex)
        {
            throw new InvalidOperationException($"{input.GetType()} does not support the type '{typeof(TValue)}'.", ex);
        }
    }
 public static bool TryParseSelectableValueFromString <TValue>(this InputBase <TValue> input, string?value, [MaybeNullWhen(false)] out TValue result, [NotNullWhen(false)] out string?validationErrorMessage)
 {
     try
     {
         if (BindConverter.TryConvertTo <TValue>(value, CultureInfo.CurrentCulture, out var parsedValue))
         {
             result = parsedValue;
             validationErrorMessage = null;
             return(true);
         }
         else
         {
             result = default;
             validationErrorMessage = $"The {input.DisplayName} field is not valid.";
             return(false);
         }
     }
     catch (InvalidOperationException ex)
     {
         throw new InvalidOperationException($"{input.GetType()} does not support the type '{typeof(TValue)}'.", ex);
     }
 }
        internal virtual void UpdateText(IList <Pair <string, string> > _paths)
        {
            if (!_isLive)
            {
                _text = Text;
                BindingOperations.ClearBinding(this, TextProperty);
                Text = _text;
                return;
            }

            if (!_updating)
            {
                _updating = true;

                BindingOperations.ClearBinding(this, TextProperty);
                MultiBinding binding = new MultiBinding();

                binding.Converter = ConverterSelector();

                binding.Mode = BindingMode.TwoWay;
                binding.UpdateSourceTrigger   = UpdateSourceTrigger.Default;
                binding.NotifyOnSourceUpdated = true;
                binding.NotifyOnTargetUpdated = true;
                //binding.Delay = 10;


                InputBase text = null;

                //update text
                if (_paths != null && State != null)
                {
                    foreach (var item in _paths)
                    {
                        var input = (Input)GetValueByPath(State, string.Format("Inputs[{0}]", item.A));
                        if (input != null)
                        {
                            var val = input.Elements.Where(x => (x is InputBase) && (x as InputBase).Name == item.B).FirstOrDefault();

                            if (val != null && val is InputBase && !_isTable)
                            {
                                if (text == null)
                                {
                                    text = (val as InputBase);
                                }
                                else
                                {
                                    var prop = val.GetType().GetProperty(val is InputImage ? MappedImageProperty : MappedTextProperty);
                                    if (prop != null)
                                    {
                                        var iprop = text.GetType().GetProperty(val is InputImage ? MappedImageProperty : MappedTextProperty);
                                        if (iprop != null)
                                        {
                                            prop.SetValue(val, iprop.GetValue(text));
                                        }
                                    }
                                }
                            }

                            Binding b = new Binding(val is InputImage ? MappedImageProperty : MappedTextProperty);
                            b.Source = val;
                            b.Mode   = BindingMode.TwoWay;
                            b.UpdateSourceTrigger = UpdateSourceTrigger.Default;
                            binding.Bindings.Add(b);
                        }
                    }
                }

                BindingOperations.SetBinding(this, TextProperty, binding);

                if (text != null && !_isTable)
                {
                    var iprop = text.GetType().GetProperty(text is InputImage ? MappedImageProperty : MappedTextProperty);
                    if (iprop != null)
                    {
                        Text = (string)iprop.GetValue(text);
                    }
                }

                _updating = false;
            }
        }