I have this datagrid which shows the following data when i click on add button. what i want is to show the grand_total at the bottom of the grid Dynamically(the area is highlighted in in yellow color) i have search alot but i am unable to access any datagrid footer or things like that, also i am very new in WPF
My Xaml CODE:
<DataGrid x:Name="dataGrid" CanUserAddRows="True" ItemsSource="{Binding ''}" AutoGenerateColumns="False" HorizontalAlignment="Left" VerticalAlignment="Top" Height="207" Width="507" IsReadOnly="True" Margin="0,66,0,0">
<DataGrid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF23B4EA" Offset="0"/>
<GradientStop Color="#FF23D2EE" Offset="0.992"/>
</LinearGradientBrush>
</DataGrid.Background>
<DataGrid.Columns>
<DataGridTextColumn x:Name="product_name" Header="Product" Binding="{Binding Title}" Width="*"/>
<DataGridTextColumn x:Name="unit_price" Header="Unit Price" Binding="{Binding Price}" Width="*"/>
<DataGridTextColumn x:Name="quantity" Header="Quantity" Binding="{Binding Quantity}" Width="*"/>
<DataGridTextColumn x:Name="Total" Header="Total" Binding="{Binding Total_Price}" Width="*"/>
<DataGridTemplateColumn Width="*" Header="Operation">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<Button Content="Delete" x:Name="btnDelete"
Click="btnDelete_Click"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Thats how i am setting the grid data:
int q, p;
q = int.Parse(QuantityTextbox.Text);
p = int.Parse(PriceTextbox.Text);
double T_price = q * p;
var data = new Test
{
Title = titleTextbox.Text,
Price = PriceTextbox.Text,
Quantity = QuantityTextbox.Text,
Total_Price = T_price.ToString()
};
dataGrid.Items.Add(data);
Where Test is the class:
public class Test
{
public string Title { get; set; }
public string Price { get; set; }
public string Quantity { get; set; }
public string Total_Price { get; set; }
public string grand_total { get; set; }
}
Please i need a simplified solution for this because i am new in WPF
Add the following using statement to top of the code file used to access datagrid
Create a TextBlock to show updated total from code behind.
After your code adding data, calculate the total using items in datagrid
The TextBlock and DataGrid can be placed in a Grid and you can then position the TextBlock to where you need it to be.