xamarin.forms - xamarin 形式:如何在列表视图中将价格和数量相乘
问题描述
我有列表视图,其中有 qty 和 itemPrice,我需要将这两个相乘并在标签中显示 totalprice。列表视图中的总价标签也是我的代码
<ListView x:Name="mylistview">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout >
<Label HorizontalOptions="Center"
Text="{Binding Source={x:Reference stepper}, StringFormat='Qty. {0:N}', Path=Value}"
FontSize="11"
TextColor="Black" />
<Stepper ValueChanged="stepper_ValueChanged"
Minimum="0"
Maximum="10"
x:Name="stepper"
Value="{Binding Qty}"
Increment="1"
HorizontalOptions="LayoutOptions.Center"
VerticalOptions="LayoutOptions.CenterAndExpand" />
<Label Text="{Binding itemPrice, StringFormat='Unit Price - RS. {0:N}'}"
FontSize="11"
TextColor="LightGray" />
<Label HorizontalOptions="End"
VerticalOptions="End"
Text="{Binding totalprice}"
FontSize="15"
TextColor="#da3043" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
解决方案
在您的模型中为 TotalPrice 创建一个只读属性并绑定到它
<Label Text="{Binding TotalPrice}" ... />
public decimal TotalPrice {
get {
return itemPrice * Qty;
}
}
推荐阅读
- amp-html - AMP 项目中的 LCP (PageSpeed) - 样板 amp 标签变得更糟 LCP
- sql - SQL 一些选择合二为一(或从一列中获取两列)
- flutter - Flutter - 我可以用 Hero 包装每个小部件来为它们设置动画吗
- javascript - 如何正确传递查询字符串参数?角
- javascript - 可缩放以继续绘制画布时如何获得鼠标的实际位置?
- javascript - 反应原生 js。按下开始按钮时没有显示
- firebase - 哈希图是否需要事务
- ios - POSIX 套接字能否在 iOS Swift 和 Windows 10 C/C++ 之间工作?
- angular - 角度标签集标签顺序未维护
- c# - 旋转时Xamarin Android BottomNavigationView不可见