public async Task LoadAsync(CancellationToken cancellationToken) { InitializeComponent(); if (_widgets == null) { // creating a list of widget’s IDs _widgets = Resources.MergedDictionaries.SelectMany(x => x.Keys.OfType <string>()).Where(x => x.StartsWith(@"Widget")).ToArray(); } var widgets = new Dictionary <string, WidgetEntry>(_widgets.Length); foreach (var key in _widgets) { Logging.Debug(key); widgets[key] = new WidgetEntry(key, (FrameworkElement)FindResource(key)); Logging.Debug(widgets[key]); await Task.Delay(10, cancellationToken); if (cancellationToken.IsCancellationRequested) { return; } } DataContext = new ViewModel(widgets); }
public async Task LoadAsync(CancellationToken cancellationToken) { InitializeComponent(); if (_widgets == null) { // creating a list of widget’s IDs _widgets = Resources.MergedDictionaries.SelectMany(x => x.Keys.OfType<string>()).Where(x => x.StartsWith(@"Widget")).ToArray(); } var widgets = new Dictionary<string, WidgetEntry>(_widgets.Length); foreach (var key in _widgets) { widgets[key] = new WidgetEntry(key, (FrameworkElement)FindResource(key)); await Task.Delay(10, cancellationToken); if (cancellationToken.IsCancellationRequested) return; } DataContext = new ViewModel(widgets); }