Background size and color bugging when I launch the project.

AdrianoFSilvaAdrianoFSilva Member ✭✭
edited June 7 in Xamarin.Forms

Im having a problem with the color and size of my button when on render without any action on them and when I do some action they turn to normal. I created a button and a frame, the frame only has a problem with the color and the button has a problem with the size and color.

Look like this:

The left one is the Frame and the right one is the Button.
What I expected:

Xaml code:
<telerikPrimitives:RadBorder x:Name="BorderMinus" BorderColor="#3F3C42" BorderThickness="1" Grid.Column="0" Grid.Row="1" Margin="3,2,2,2"> <Frame x:Name="QntMinus" Padding="0" BackgroundColor="{Binding DecrementQuantityCommandEnabled, Source={x:Reference ExtendedContentView}, Converter={StaticResource Batata}, ConverterParameter={x:Reference Name=MainColorGrid2}}"> <Label Text="-" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/> <Frame.GestureRecognizers> <TapGestureRecognizer Command="{Binding DecrementQuantityCommand, Source={x:Reference ExtendedContentView}}"/> </Frame.GestureRecognizers> </Frame> </telerikPrimitives:RadBorder> <Label x:Name="QntLabel" Text="{Binding SelectedSize.Quantity, Source={x:Reference ExtendedContentView}}" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" TextColor="White" Grid.Column="1" Grid.Row="1"/> <telerikPrimitives:RadBorder x:Name="BorderPlus" BorderColor="#FF8A00" BorderThickness="1" Grid.Column="2" Grid.Row="1" Margin="2,2,3,2"> <Button x:Name="QntPlus" Text="+" Padding="0" Command="{Binding IncrementQuantityCommand, Source={x:Reference ExtendedContentView}}" Margin="-1" BackgroundColor="{Binding IncrementQuantityCommandEnabled, Source={x:Reference ExtendedContentView}, Converter={StaticResource Batata}, ConverterParameter={x:Reference Name=MainColorGrid2}}"/> </telerikPrimitives:RadBorder>

Code-behind:
public partial class ExtendedButton : ContentView
{
public bool IncrementQuantityCommandEnabled { get; set; }
public bool DecrementQuantityCommandEnabled { get; set; }
public ICommand IncrementQuantityCommand { get; set; }
public ICommand DecrementQuantityCommand { get; set; }

        public void IncrementQuantity()
        {           
            if (SelectedSize.IncrementQuantity())
            {
                if (SelectedSize.Quantity == 10)
                {
                    IncrementQuantityCommandEnabled = false;
                }

                DecrementQuantityCommandEnabled = true;
            }            
        }

        public void DecrementQuantity()
        {
            if (SelectedSize.DecrementQuantity())
            {
                if (SelectedSize.Quantity == 1)
                {
                    DecrementQuantityCommandEnabled = false;
                }

                IncrementQuantityCommandEnabled = true;
            }
        }

    public ExtendedButton()
        {
            InitializeComponent();

            SelectedSize = null;
            Tapped = false;
            IsExtended = false;

            IncrementQuantityCommandEnabled = true;
            DecrementQuantityCommandEnabled = true;
            IncrementQuantityCommand = new Command(() => IncrementQuantity(), () => IncrementQuantityCommandEnabled);
            DecrementQuantityCommand = new Command(() => DecrementQuantity(), () => DecrementQuantityCommandEnabled);
        }
    }

     public class IsActiveToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Grid grid = parameter as Grid;
            Color mainColorDisabled = Color.Green;
            Color mainColor = Color.Pink;

            bool first = true;

            foreach (var item in grid.Children)
            {
                var label = item as Label;

                if (first)
                {
                    mainColor = label.BackgroundColor;
                    first = false;
                }
                else
                {
                    mainColorDisabled = label.BackgroundColor;
                }
            }

            var isActive = (bool)value;

            if (isActive)
            {
                return mainColor;
            }
            else
            {
                return mainColorDisabled;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    Though you use the Frame on the left , why don't you use frame on the right one as well?

Sign In or Register to comment.