My program has network functionality so to avoid messagebox spam in case of network problem i display errors from a collection.
internal class VM_Main
{ ...
public ObservableCollection<string> Errors { get; } = new observableCollection<string>();
...
}
This collection is displayed in my XAML window.
public MainWindow()
{ ...
vm_Main = new VM_Main();
dgdErrors.ItemsSource = vm_Main.Errors;
...
}
This is OK.
My problem is when i use objects from other classes in variables. How can I send information to the errors collection to report an error?
internal class VM_Main
{ ...
public ObservableCollection<string> Errors { get; } = new observableCollection<string>();
...
List <Customers> allCustomers = new List<Customer>()
}
public class Customer
{ ...
public string Name { get; set; }
...
public Customer()
{
try{ // Network work }
catch (Exception ex) { ????? Errors.Add(ex.Message) ???? }
}
...
}
"Errors doesn't exist in the current context." Of course, but how am I supposed to do ?