My DataGrid's values does not seem to update when the values in it is modified.
I have tried:
- Setting the Mode to
TwoWay - Using
BindableCollection(from Caliburn.Micro) - Using
ObservableCollection - Using a
List - Merging
QuotationViewModelwithTableViewModel - Adding an item in
Workand removing it - Using
x:Name="Work"in the DataGrid instead of ItemsSource
TableViewModel.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.
I just turned to creating a new
BindableCollectionwhenever I want to update it.Last time
CalculateQuotationswas 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 callOnPropertyChanged(nameof(Work))explicitly it didn't fix it, but this puts a new object and it updates everything.