I have got client-server app, where client gets data from server and saves it in static class:
public static class DataStructure
{
//! Значение каждой переменной
public static Value AxisX = new Value(@"axis_x", Dividers.AxisX);
public static Value AxisY = new Value(@"axis_y", Dividers.AxisY);
public static Value AxisZ = new Value(@"axis_z", Dividers.AxisZ);
public static Value Temp = new Value(@"temp", Dividers.Temp);
public static Value GirX = new Value(@"gir_x", Dividers.GirX);
public static Value GirY = new Value(@"gir_y", Dividers.GirY);
public static Value GirZ = new Value(@"gir_z", Dividers.GirZ);
...
public static List<Value> ListOfValues = new List<Value>
{
AxisX,
AxisY,
AxisZ,
Temp,
GirX,
GirY,
GirZ,
....
}
...
Client-side app has GUI (WPF with MVVM pattern). Client receives data from server every 1 second and they must be displayed in window. Screenshot (click)
If I want it, I must RaisePropertyChanged()
, but I don't want to interfere in DataSctructure
class and make properties with RaisePropertyChanged()
. What is the best way to do it? I can create a lot of properties in ViewModel (such as AxisX
, AxisY
, ...) and assign them data from ListOfValues
, but I think it is irrationally.
Or, may be, I must change structure of application?
UPDATE 1:
public class Value
{
public Value(string name, double divider = 1.0)
{
Name = name;
Divider = divider;
HexCode = string.Empty;
IntValue = 1;
PhysValue = 1.0;
}
public readonly string Name;
public readonly double Divider;
public string HexCode { get; private set; }
public int IntValue { get; private set; }
public double PhysValue { get; private set; }
}
You can either wrap each
Value
in a property on your viewmodel and callPropertyChanged
there, or you can modify theDataStructure
class to firePropertyChanged
. You will have to makeDataStructure
non static in order to implement INotifyPropertyChanged on it, however.Speaking of which, why are you storing mutable data in a static class? That is a very bad idea...
Look for instance at my answer here: in this case
Then if Value is a class with properties (like
IntValue
andPhysValue
, i.e. with a getter at least), you already have a collection (a list) bindable to a (read only) Control (aDataGrid
).for example
Of course you have to elaborate more to implement your desired screenshot