Код: Выделить всё
public partial class ItemViewModel : ObservableObject
{
[ObservableProperty]
double _quantity;
[ObservableProperty]
double _price;
[ObservableProperty]
string _selectedProperty;
[RelayCommand]
void SetSelectedProperty(string selectedProperty)
=> SelectedProperty = selectedProperty;
}
Код: Выделить всё
public partial class Numpad : ContentView
{
double? _value;
public static readonly BindableProperty TextProperty =
BindableProperty.Create(
propertyName: nameof(Text),
returnType: typeof(string),
defaultValue: "0",
defaultBindingMode: BindingMode.TwoWay,
declaringType: typeof(Numpad),
propertyChanged: (bindable, oldValue, newValue) =>
{
var @this = (Numpad)bindable;
((Command)@this.UpCommand).ChangeCanExecute();
((Command)@this.DownCommand).ChangeCanExecute();
});
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public ICommand UpCommand { get; }
public ICommand DownCommand { get; }
public Numpad()
{
UpCommand = new Command(
execute: () =>
{
Text = $"{_value + 1}";
},
canExecute: () =>
{
if (double.TryParse(Text, out double x))
{
_value = x;
return true;
}
_value = null;
return false;
}
);
DownCommand = new Command(
execute: () =>
{
Text = $"{_value - 1}";
},
canExecute: () =>
{
if (double.TryParse(Text, out double x))
{
_value = x;
return _value > 0;
}
_value = null;
return false;
}
);
InitializeComponent();
}
}
Код: Выделить всё
Код: Выделить всё
public MainPage()
{
InitializeComponent();
BindingContext = new ItemViewModel { Quantity = 3, Price = 5 };
}
Код: Выделить всё
- Нажатие одной из первых двух кнопок должно связать текст на цифровой клавиатуре< /code> на Quantity или UnitPrice.
- Нажатие любой кнопки цифровой клавиатуры должно изменить свойство Text выбранной кнопки. из первых двух кнопок.
В чем виноват?
Подробнее здесь: https://stackoverflow.com/questions/793 ... cked-butto
Мобильная версия