См. Следующий код
в xaml
<StackLayout
Orientation="Horizontal"
HorizontalOptions="EndAndExpand"
VerticalOptions="Center">
<Button
HeightRequest="40"
WidthRequest="40"
Clicked="ClickMinus"
Text="-"
BackgroundColor="White"
TextColor="Green"
BorderColor="Green"/>
<Entry
x:Name="edt_quantity"
Text="0"/>
<Button
WidthRequest="40"
HeightRequest="40"
Clicked="ClickPlus"
Text="+"
BackgroundColor="White"
TextColor="Green"
BorderColor="Green"/>
</StackLayout>
в xaml.cs
private void ClickPlus(object sender, EventArgs e)
{
int num = int.Parse(edt_quantity.Text)+1;
edt_quantity.Text = num.ToString();
}
private void ClickMinus(object sender, EventArgs e)
{
int num = int.Parse(edt_quantity.Text)-1;
edt_quantity.Text = num.ToString();
}
ЕслиВы хотите реализовать это в viewcell. Вы можете создать подкласс viewcell.
<ListView x:Name="MyListView"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<local:MyViewCell Height="100" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
И в пользовательской viewcell
в xaml
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App6.ViewCell1">
<ViewCell.View>
<AbsoluteLayout>
//...
<StackLayout
AbsoluteLayout.LayoutBounds="1,0,0.35,1"
AbsoluteLayout.LayoutFlags="All"
Orientation="Horizontal"
>
<Button
VerticalOptions="Center"
HeightRequest="30"
WidthRequest="30"
Clicked="BtnMinus_Clicked"
Text="-"
x:Name="btnMinus"
FontSize="12"
BackgroundColor="White"
TextColor="Green"
BorderColor="Green"/>
<Entry
Keyboard="Numberic"
x:Name="myEntry"
Text="0"
FontSize="12"/>
<Button
x:Name="btnAdd"
VerticalOptions="Center"
WidthRequest="30"
HeightRequest="30"
Clicked="BtnAdd_Clicked"
Text="+"
FontSize="12"
BackgroundColor="White"
TextColor="Green"
BorderColor="Green"
/>
</StackLayout>
</AbsoluteLayout>
</ViewCell.View>
</ViewCell>
в xaml.cs
public partial class MyViewCell: ViewCell
{
public MyViewCell()
{
InitializeComponent ();
}
private void BtnMinus_Clicked(object sender, EventArgs e)
{
int num = int.Parse(myEntry.Text) - 1;
myEntry.Text = num.ToString();
}
private void BtnAdd_Clicked(object sender, EventArgs e)
{
int num = int.Parse(myEntry.Text) + 1;
myEntry.Text = num.ToString();
}
}