Reputation: 106
My DataGrid's values does not seem to update when the values in it is modified.
I have tried:
TwoWay
BindableCollection
(from Caliburn.Micro)ObservableCollection
List
QuotationViewModel
with TableViewModel
Work
and removing itx:Name="Work"
in the DataGrid instead of ItemsSourceTableViewModel.cs
public class TableViewModel : Screen
{
[ ... ]
public QuotationViewModel QuotationViewModel { get; set; }
public void Update()
{
NotifyOfPropertyChange(() => WoodTotal);
QuotationViewModel.Update();
}
}
TableView.xaml
<!--Total-->
<ContentControl Grid.Column="1"
cal:View.Model="{Binding Path=QuotationViewModel}"/>
QuotationViewModel.cs
public class QuotationViewModel : INotifyPropertyChanged
{
private readonly TableViewModel _tableViewModel;
public QuotationViewModel(TableViewModel tableViewModel)
{
_tableViewModel = tableViewModel;
}
public BindableCollection<ICanCalculate> Work { get; set; } = App.Config.Work;
public void Update()
{
QuotationRow.CalculateQuotations(_tableViewModel.WoodTotal);
OnPropertyChanged(nameof(Work));
}
}
QuotationView.xaml
<DataGrid ItemsSource="{Binding Path=Work, Mode=TwoWay}" />
Repository: https://github.com/hizamakura/Furniture
As seen in this gif, the value updates when I double click it, it should update without having to double click it. I know that the bindings are correct because when I update Value, say of Milling
to 0.20
, the Total
will change to 20%
that of the Mahogany.
Upvotes: 0
Views: 214
Reputation: 106
I just turned to creating a new BindableCollection
whenever I want to update it.
public BindableCollection<ICanCalculate> Work { get; set; } = App.Config.Work;
public void Update()
{
Work.CalculateQuotations(_tableViewModel.WoodTotal);
Work = new BindableCollection<ICanCalculate>(Work);
}
Last time CalculateQuotations
was just a method that operates on the same object, therefore the property isn't set again, only the properties inside is changed. i.e. the property is still the same object.
Even if I call OnPropertyChanged(nameof(Work))
explicitly it didn't fix it, but this puts a new object and it updates everything.
Upvotes: 0