示例#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);
        }