Accessing a resource dictionary by name is a bit problematic since it doesn't derive from FrameworkElement
and thus doesn't have a Name
property. If it had, you could do the following:
Application.Current.Resources.MergedDictionaries
.First(x => x.Name == "dict")["DatabaseViewModel"] as Shared.ViewModels.DatabaseViewModel;
However, instead of filtering by name, you can filter by source:
Application.Current.Resources.MergedDictionaries
.First(x => x.Source.OriginalString == "ResourceDict.xaml")["DatabaseViewModel"] as Shared.ViewModels.DatabaseViewModel;