I dont really see where i should put that code in a MVVM practice. should i create the entire datagrid in the VM ? should i trigger on some ItemsSource updated event in the code behind ? ...
first i do create a Data class that contain my Records :
//the BindableBase is from prism but is same as implementation of INotifyPropertyChangedpublic class Data : BindableBase { private ObservableCollection<Record> _records = new(); public ObservableCollection<Record> Records { get { return _records; } set { SetProperty(ref _records, value); } } }
//the BindableBase is from prism but is same as implementation of INotifyPropertyChangedpublic class Data : BindableBase { private ObservableCollection<Record> _records = new(); public ObservableCollection<Record> Records { get { return _records; } set { SetProperty(ref _records, value); } } }
record :
public class Record { private readonly ObservableCollection<Property> properties = new ObservableCollection<Property>(); public Record(params Property[] properties) { foreach (var property in properties) Properties.Add(property); } public ObservableCollection<Property> Properties { get { return properties; } } }
public class Record { private readonly ObservableCollection<Property> properties = new ObservableCollection<Property>(); public Record(params Property[] properties) { foreach (var property in properties) Properties.Add(property); } public ObservableCollection<Property> Properties { get { return properties; } } }
property
public class Property { public Property(string name, object value) { Name = name; Value = value; } public string Name { get; private set; } public object Value { get; set; } }
public class Property { public Property(string name, object value) { Name = name; Value = value; } public string Name { get; private set; } public object Value { get; set; } }
in your VM you can instanciate your prop with
public class SomeViewModel: ViewModelBase{ private Data _data = new(); public Data Data { get { return _data; } set { SetProperty(ref _data, value); } }}
public class SomeViewModel: ViewModelBase{ private Data _data = new(); public Data Data { get { return _data; } set { SetProperty(ref _data, value); } }}
So I have a bunch of classes that are derived from some base class. I have classes (collectors) that have a methods that returns collections of these classes. I also have a TabControl where each ta...