using System.Collections.ObjectModel; using System.Linq; using Microsoft.Extensions.DependencyInjection; using data.RemoteData.RemoteDataBase; using System; namespace Presence.Desktop.ViewModels { public class MainWindowViewModel { public ObservableCollection GroupNames { get; set; } = new ObservableCollection(); private readonly IServiceProvider _services; public MainWindowViewModel(IServiceProvider services) { _services = services; GroupNames.Add("Group 1"); GroupNames.Add("Group 2"); GroupNames.Add("Group 3"); LoadGroupNames(); } private void LoadGroupNames() { using (var context = _services.GetRequiredService()) { var groupNames = context.Groups.Select(g => g.Name).ToList(); foreach (var name in groupNames) { GroupNames.Add(name); } } } } }