I have developed some MVVM based WPF code and am in need of some minor refactoring but prior to doing that I need to decide the best architecture.
I originally started with an application that could present several similar (but separate) representations of my data. Let's call it RecordsViewModel which had a corresponding RecordsView. As time went on, I introduced a SettingsViewModel which was passed into the constructor of the RecordsViewModel and published visibly (allowing RecordsView to use it). The SettingsViewModel is registered to so that changes are reflected in all of my views.
Now I want to split RecordsView a little because it now contains two distinct views.
The problem I have is:
- the new (
RecordsMainViewandRecordsAlternativeView) both want to see Settings. - unlike the earlier
RecordsViewwhich is programmatically instantiated, these new views are instantiated from Xaml (default constructor).
So my options seem to be:
- Walk the Tree Model upwards to find a parent with a Settings
- Make Settings a
DependencyPropertyon the controls and make the Xaml join the Property to the instance. - Make
SettingsViewModela Singleton.
Any other, better, options? Which would you consider best?