예제 #1
0
        internal static IEnumerable <Binding> BindImages(object target, IControllerBase source)
        {
            var bindings           = new List <Binding>();
            var bindableProperties = target.GetType().GetProperties().Where(p => p.CustomAttributes.Any(a => a.AttributeType.Name == "BindImageAttribute"));

            foreach (var bindableProperty in bindableProperties)
            {
                var bindableAttribute = bindableProperty.GetCustomAttribute(typeof(BindImageAttribute)) as BindImageAttribute;
                if (bindableAttribute == null)
                {
                    continue;
                }

                var binding = source.SetBinding <IControllerBase, ImageView>(bindableAttribute.Source, bindableProperty.GetValue(target)).WhenSourceChanges(() =>

                {
                    var b  = (byte[])source.GetType().GetProperty(bindableAttribute.Source).GetValue(source);
                    var iv = ((ImageView)bindableProperty.GetValue(target));
                    if (b != null && b.Any())
                    {
                        iv.SetImageBitmap(BitmapFactory.DecodeByteArray(b, 0, b.Length));
                        iv.Invalidate();
                    }
                });
                bindings.Add(binding);
            }
            return(bindings);
        }
예제 #2
0
        internal static void BindCommands(object target, IControllerBase source)
        {
            var bindableProperties = target.GetType().GetProperties().Where(p => p.CustomAttributes.Any(a => a.AttributeType.Name == "BindCommandAttribute"));

            foreach (var bindableProperty in bindableProperties)
            {
                var bindableAttribute = bindableProperty.GetCustomAttribute(typeof(BindCommandAttribute)) as BindCommandAttribute;
                if (bindableAttribute != null)
                {
                    bindableProperty.GetValue(target).SetCommand(bindableAttribute.Target, (ICommand)source.GetType().GetProperty(bindableAttribute.Source).GetValue(source));
                }
            }
        }