I have the following Grid, I would like to know how can I do so that when I leave the Gain or Spend field it updates the Total?
If there is another way to do it, I'm happy to meet you.
Total = (Gain - Expense)
private void txtGanho_LostFocus(object sender, RoutedEventArgs e)
{
TextBox txtGanho = (TextBox)sender;
//Aqui eu tenho o valor do Ganho, como posso encontrar na Grid os TextBox com Gasto e Total
}
private void txtGasto_LostFocus(object sender, RoutedEventArgs e)
{
TextBox txtGasto = (TextBox)sender;
//Aqui tenho o valor do Gasto, como posso encontrar na Grid os TextBox com Ganho e Total
}
.xaml file
<DataGrid x:Name="dgControleFinanceiro" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding Id}" IsReadOnly="True" />
<DataGridTextColumn Header="Data" Binding="{Binding Data}" IsReadOnly="True"/>
<DataGridTemplateColumn Header="Ganho do dia" IsReadOnly="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Name="txtGanho" Text="{Binding Ganho}" LostFocus="txtGanho_LostFocus"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Gasto do dia" IsReadOnly="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Name="txtGasto" Text="{Binding Gasto}" LostFocus="txtGasto_LostFocus"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Total do dia" IsReadOnly="true">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Name="txtTotal" Text="{Binding Total}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>