I am trying display the total value of the items selected, the selected items are in a ListView. The values of item appear in the list but I want the total value of items to display inside a textbox. My code is below:
Basket.xaml
private static ObservableCollection<Menu.PassedData> passedData = new ObservableCollection<Menu.PassedData>();
private double totalValue;
public double TotalValue
{
get { return totalValue; }
set
{
totalValue = value;
OnPropertyChanged("TotalValue");
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Menu.PassedData data = e.Parameter as Menu.PassedData;
if (data != null) //If data is not 0
{
PassedData.Add(data); //Increment data in list view
double tempTotalValue = 0;
foreach (var record in PassedData)
{
tempTotalValue = tempTotalValue + record.Value;
}
TotalValue = tempTotalValue;
}
}
}
The list in which the values are stored(Basket.xaml)
<ListBox x:Name="listBox1" HorizontalAlignment="Left" Height="265" Margin="278,175,0,0" VerticalAlignment="Top" Width="112">
<ListView x:Name="PriceView" ItemsSource="{Binding PassedData}" HorizontalAlignment="Left" VerticalAlignment="Center">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<!--<TextBox Grid.Column="0" Text="{Binding Name}" IsReadOnly="True" /> !-->
<TextBox Grid.Column="1" Text="{Binding Value}" IsReadOnly="True" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ListBox>
So basically add up the Value column in listview and display it in a textbox.