Пример #1
0
        AImageButton CreateImageButton(Context context, BindableObject bindable, BindableProperty property, int defaultImage, int leftMargin, int rightMargin, string tag)
        {
            var result = new AImageButton(context);

            result.Tag = tag;
            result.SetPadding(0, 0, 0, 0);
            result.Focusable = false;
            result.SetScaleType(ImageView.ScaleType.FitCenter);

            if (bindable.GetValue(property) is ImageSource image)
            {
                AutomationPropertiesProvider.SetContentDescription(result, image, null, null);
            }

            ((ImageSource)bindable.GetValue(property)).LoadImage(MauiContext, (r) =>
            {
                result.SetImageDrawable(r?.Value);
            });

            var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent)
            {
                LeftMargin  = leftMargin,
                RightMargin = rightMargin
            };

            result.LayoutParameters = lp;
            lp.Dispose();
            result.SetBackground(null);

            return(result);
        }
Пример #2
0
        AImageButton CreateImageButton(Context context, ImageSource image, int defaultImage, int leftMargin, int rightMargin)
        {
            var result = new AImageButton(context);

            result.SetPadding(0, 0, 0, 0);
            result.Focusable = false;

            string defaultHint        = null;
            string defaultDescription = null;

            AutomationPropertiesProvider.SetContentDescription(result, image, ref defaultDescription, ref defaultHint);

            SetImage(result, image, defaultImage);
            var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent)
            {
                LeftMargin  = leftMargin,
                RightMargin = rightMargin
            };

            result.LayoutParameters = lp;
            lp.Dispose();
            result.SetBackground(null);

            return(result);
        }
Пример #3
0
        AImageButton CreateImageButton(Context context, BindableObject bindable, BindableProperty property, int defaultImage, int leftMargin, int rightMargin, string tag)
        {
            var result = new AImageButton(context);

            result.Tag = tag;
            result.SetPadding(0, 0, 0, 0);
            result.Focusable = false;
            result.SetScaleType(ImageView.ScaleType.FitCenter);

            string defaultHint        = null;
            string defaultDescription = null;

            if (bindable.GetValue(property) is ImageSource image)
            {
                AutomationPropertiesProvider.SetContentDescription(result, image, ref defaultDescription, ref defaultHint);
            }

            _shellContext.ApplyDrawableAsync(bindable, property, drawable =>
            {
                if (drawable != null)
                {
                    result.SetImageDrawable(drawable);
                }
                else if (defaultImage > 0)
                {
                    result.SetImageResource(defaultImage);
                }
                else
                {
                    result.SetImageDrawable(null);
                }
            });
            var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent)
            {
                LeftMargin  = leftMargin,
                RightMargin = rightMargin
            };

            result.LayoutParameters = lp;
            lp.Dispose();
            result.SetBackground(null);

            return(result);
        }