从列表框数据计算总价 [英] Calculate total price from list box data
本文介绍了从列表框数据计算总价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有一个列表框将为产品价格绑定数据.如何计算所有商品的总价?
我的电话page.xaml如下:
Hi, i had a listbox will binding the data for price of the product. How can i calculate the total price of all of it?
My phone page.xaml is as below:
<ListBox Height="650" HorizontalAlignment="Left" Margin="11,17,0,0" Name="listBox1" VerticalAlignment="Top" Width="434" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ProdId}"/>
<TextBlock Text="{Binding ProdPrice}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想计算绑定到产品价格的文本块上的所有总价,然后将其放置到文本块中.
这是我从数据库检索数据并将其放入列表框的代码.
I want to calculate all total price that at textblock that bind to Product Price and place it to a textblock.
And this is the code i retrieve data from database and put into listbox.
public MainPage()
{
InitializeComponent();
Service1Client svc = new Service1Client();
svc.GetAllModelsCompleted += new EventHandler<GetAllModelsCompletedEventArgs>(svc_GetAllModelsCompleted);
svc.GetAllModelsAsync();
}
void svc_GetAllModelsCompleted(object sender, GetAllModelsCompletedEventArgs e)
{
listBox1.ItemsSource = e.Result;
}
推荐答案
请尝试事件SelectedIndexChanged,以便获取值并进行适当的计算.
问候,
T
Hi try the event SelectedIndexChanged, so as to get the value and make appropriate calculation.
Regards,
T
这篇关于从列表框数据计算总价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文