Кнопки глючат на lauch и ярлык внутри них исчезает при использовании команд - PullRequest
0 голосов
/ 06 июня 2019

Я использую некоторые команды, чтобы сделать мои кнопки более динамичными, и у меня есть некоторые ошибки.Один из них - когда я запускаю свою программу, стиль моей ошибки кнопок выглядит так:

sample

Вместо этого:

correct

Мне показывается правильный стиль, только когда вызывается код команды.

Вторая проблема заключается в том, что мой текст не отображается.

Код моих кнопок:

<telerikPrimitives:RadBorder x:Name="BorderMinus" BorderColor="#3F3C42" BorderThickness="1" Grid.Column="0" Grid.Row="1" Margin="3,2,2,2">
   <Button x:Name="QntMinus" Text="-" Padding="0" Command="{Binding DecrementQuantityCommand, Source={x:Reference ExtendedContentView}}" Margin="-1" BackgroundColor="{Binding DecrementQuantityCommandEnabled, Source={x:Reference ExtendedContentView}, Converter={StaticResource Batata}, ConverterParameter={x:Reference Name=MainColorGrid2}}"/>
</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>

И используемый мной укрыватель реализован в xaml следующим образом:

<ContentView.Resources>
   <ResourceDictionary>
      <local:IsActiveToColorConverter x:Key="Batata" />
   </ResourceDictionary>
</ContentView.Resources>

Мой код:

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();

      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();
   }
}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...