Ejemplo n.º 1
0
        internal void Apply(BindableObject target, bool fromStyle = false)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (Property == null)
            {
                return;
            }

            object originalValue = target.GetValue(Property);

            if (!Equals(originalValue, Property.DefaultValue))
            {
                _originalValues.Remove(target);
                _originalValues.Add(target, originalValue);
            }

            var dynamicResource = Value as DynamicResource;
            var binding         = Value as BindingBase;

            if (binding != null)
            {
                target.SetBinding(Property, binding.Clone(), fromStyle);
            }
            else if (dynamicResource != null)
            {
                target.SetDynamicResource(Property, dynamicResource.Key, fromStyle);
            }
            else
            {
                target.SetValue(Property, Value, fromStyle);
            }
        }
Ejemplo n.º 2
0
 internal override void SetUp(BindableObject bindable)
 {
     if (Binding != null)
     {
         bindable.SetBinding(_boundProperty, Binding.Clone());
     }
 }
        public static void SetOnAppTheme <T>(this BindableObject self, BindableProperty targetProperty, T light, T dark, T defaultValue = default)
        {
            ExperimentalFlags.VerifyFlagEnabled(nameof(BindableObjectExtensions), ExperimentalFlags.AppThemeExperimental, nameof(BindableObjectExtensions), nameof(SetOnAppTheme));

            var appTheme = new OnAppTheme <T> {
                Light = light, Dark = dark, Default = defaultValue
            };

            self.SetBinding(targetProperty, appTheme);
        }
Ejemplo n.º 4
0
        static void BindProperty(BindableObject content, BindableProperty property, Type type)
        {
            if (content.IsSet(property) || content.GetIsBound(property))
            {
                // Don't override the property if user has already set it
                return;
            }

            content.SetBinding(property,
                               new Binding(property.PropertyName,
                                           source: new RelativeBindingSource(RelativeBindingSourceMode.FindAncestor, type)));
        }
Ejemplo n.º 5
0
        public static void SetBinding(this BindableObject self, BindableProperty targetProperty, string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null,
                                      string stringFormat = null)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }
            if (targetProperty == null)
            {
                throw new ArgumentNullException("targetProperty");
            }

            var binding = new Binding(path, mode, converter, stringFormat: stringFormat);

            self.SetBinding(targetProperty, binding);
        }
        public static void SetBinding <TSource>(this BindableObject self, BindableProperty targetProperty, Expression <Func <TSource, object> > sourceProperty, BindingMode mode = BindingMode.Default,
                                                IValueConverter converter = null, string stringFormat = null)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }
            if (targetProperty == null)
            {
                throw new ArgumentNullException("targetProperty");
            }
            if (sourceProperty == null)
            {
                throw new ArgumentNullException("sourceProperty");
            }

            Binding binding = Binding.Create(sourceProperty, mode, converter, stringFormat: stringFormat);

            self.SetBinding(targetProperty, binding);
        }
Ejemplo n.º 7
0
 public static void SetOnAppTheme <T>(this BindableObject self, BindableProperty targetProperty, T light, T dark) => self.SetBinding(targetProperty, new AppThemeBinding {
     Light = light, Dark = dark
 });