Exemplo n.º 1
0
        protected BindableElement CreateField <TElement, TValue>(TValue initial) where TElement : BindableElement, INotifyValueChanged <TValue>, new()
        {
            var element = new TElement();

            element.RegisterValueChangedCallback(evt =>
            {
                var self = evt.target as BindableElement;
                using var updateEvent = FieldUpdateEvent.GetPooled(self.bindingPath, evt.newValue, self); self.SendEvent(updateEvent);
            });
            element.SetValueWithoutNotify(initial);
            return(element);
        }
Exemplo n.º 2
0
 protected BindableElement CreateField <TElement, TElementValue, TValue>(TElement element, TElementValue initial, Converter <TElementValue, TValue> converter) where TElement : BindableElement, INotifyValueChanged <TElementValue>
 {
     element.RegisterValueChangedCallback(evt =>
     {
         var self = evt.target as BindableElement;
         if (converter.Invoke(evt.newValue, out TValue result))
         {
             using var updateEvent = FieldUpdateEvent.GetPooled(self.bindingPath, result, self); self.SendEvent(updateEvent);
         }
         else
         {
             (evt.target as INotifyValueChanged <TElementValue>)?.SetValueWithoutNotify(evt.previousValue);
         }
     });
     element.SetValueWithoutNotify(initial);
     return(element);
 }
Exemplo n.º 3
0
        private BaseField <Enum> CreateField(Type type, FieldInfo fieldInfo, Enum initialValue)
        {
            BaseField <Enum> element;

            if (type.GetCustomAttribute <FlagsAttribute>() != null)
            {
                element = new EnumFlagsField(initialValue);
            }
            else
            {
                element = new EnumField(initialValue);
            }
            element.RegisterValueChangedCallback(evt =>
            {
                var self = evt.target as BindableElement;
                using var updateEvent = FieldUpdateEvent.GetPooled(self.bindingPath, evt.newValue, self); self.SendEvent(updateEvent);
            });
            element.SetValueWithoutNotify(initialValue);
            return(element);
        }