In my WPF application, I want to build a graph where I sum up a "measured" current and display this for every graph element.
I tried using the MVVM Toolkit for this and set up 2 classes:
public partial class CurrentFlow:ObservableObject
{
[ObservableProperty]
private int _id;
[ObservableProperty]
private float _current;
}
public partial class Connection:CurrentFlow
{
[ObservableProperty]
private CurrentFlow? _inflow1;
[ObservableProperty]
private CurrentFlow? _inflow2;
partial void OnInflow1Changed(CurrentFlow? value)
{
Current = value?.Current ?? 0.0f + Inflow2?.Current ?? 0.0f;
}
partial void OnInflow2Changed(CurrentFlow? value)
{
Current = value?.Current ?? 0.0f + Inflow1?.Current ?? 0.0f;
}
}
I then create the graph like this, where Powerstages is an ObservableCollection<CurrentFlow> and TerminalConnection is a Connection:
private void CreateConnections()
{
var lastConnection = TerminalConnection;
foreach (var ps in Powerstages)
{
lastConnection.Inflow1 = ps;
if (ps != Powerstages.LastOrDefault())
{
var con = new Connection { Id = ps.Id + 100000 };
lastConnection.Inflow2 = con;
lastConnection = con;
}
}
}
My problem is, that the OnInflow1Changed and OnInflow2Changed methods don't get triggered when I change the Powerstages[i].Current property.
Has anyone an idea what I am doing wrong and where I can improve?
I suspect the PropertyChanged event does not propagate, but I thought this would be the exact usecase for the [ObservableProperty]attribute.
I could manually subscribe to the currents change events, but Im hoping there is a neat way using the MVVM Toolkit.