【发布时间】:2019-03-04 07:07:32
【问题描述】:
我是 xamarin.forms 的新手。我不知道如何处理列表视图中的按钮。我想用 + 和 - 功能创建 2 个按钮。该条目将是默认值 = 0。当我单击 + 按钮时,条目将是 ++ 并且 - 当我单击 - 按钮时。任何人请告诉我我应该怎么做。 这是我的代码:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="QRScanner.Menu">
<ListView x:Name="MyListView"
ItemsSource="{Binding Items}"
ItemTapped="Handle_ItemTapped"
CachingStrategy="RecycleElement">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell
Height="100"
>
<AbsoluteLayout>
<StackLayout
AbsoluteLayout.LayoutBounds="0,0,0.65,1"
AbsoluteLayout.LayoutFlags="All"
Orientation="Horizontal">
<Image
HorizontalOptions="StartAndExpand"
WidthRequest="70"
HeightRequest="70"
VerticalOptions="CenterAndExpand"
Source="{Binding imgUrl}"
/>
<Label Text="{Binding name}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
/>
<Label
HorizontalOptions="EndAndExpand"
Text="{Binding price}"
VerticalOptions="CenterAndExpand"/>
</StackLayout>
<StackLayout
AbsoluteLayout.LayoutBounds="1,0,0.35,1"
AbsoluteLayout.LayoutFlags="All"
Orientation="Horizontal"
>
<Button
VerticalOptions="Center"
HeightRequest="30"
WidthRequest="30"
Clicked="Button_Clicked"
Text="-"
x:Name="btnMinus"
FontSize="12"
BackgroundColor="White"
TextColor="Green"
BorderColor="Green"/>
<Entry
Keyboard="Numberic"
x:Name="edt_quantity"
Text="{Binding quantity}"
FontSize="12"/>
<Button
x:Name="btnAdd"
VerticalOptions="Center"
WidthRequest="30"
HeightRequest="30"
Clicked="Button_Clicked_1"
Text="+"
FontSize="12"
BackgroundColor="White"
TextColor="Green"
BorderColor="Green"
/>
</StackLayout>
</AbsoluteLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我想从 api 获取数据,客户可以从菜单中选择数字,然后将其发送到服务器。喜欢预订应用程序。
【问题讨论】:
-
嘿,问题解决了吗?
-
对不起先生,我遇到了一些新问题,所以我没有尝试,当我尝试时,我会告诉你结果,非常感谢你的帮助。
-
是的,稍后我会告诉你
标签: listview xamarin button xamarin.forms